On 12/28/2011 11:57 AM, Rick Johnson wrote:
On Dec 27, 3:38 pm, Terry Reedy<tjre...@udel.edu>  wrote:
On 12/27/2011 1:04 PM, Rick Johnson wrote:

But this brings up a very important topic. Why do we even need triple
quote string literals to span multiple lines? Good question, and one i
have never really mused on until now.

I have, and the reason I thought of is that people, including me, too
ofter forget or accidentally fail to properly close a string literal,

Yes, agreed.

Color coding editors make it easier to catch such errors, but they were
less common in 1991.

I would say the need for triple quote strings has passed long ago.
Like you say, since color lexers are ubiquitous now we don't need
them.

And there is still uncolored interactive mode.

I don't see interactive command line programming as a problem. I mean,
who drops into a cmd line and starts writing paragraphs of string
literals? Typically, one would just make a few one-liner calls here or
there. Also, un-terminated string literal errors can be very
aggravating. Not because they are difficult to fix, no, but because
they are difficult to find! -- and sending me an error message
like...

  "Exception: Un-terminated string literal meets EOF! line: 50,466,638"

... is about as helpful as a bullet in my head!

If the interpreter finds itself at EOF BEFORE a string closes, don't
you think it would be more helpful to include the currently "opened"
strings START POSITION also?

No it wouldn't. Once you get an unterminated string literal, the string would terminate at the next string opening. Then it would fuck the parser since it will try to parse what was supposed to be a string literal as a code. For example:

hello = 'bar'
s = "boo, I missed a quote here
print 'hello = ', hello, "; s = ", s

the parser would misleadingly show that you have an unclosed string literal here:

                              vvv
print 'hello = ', hello, "; s = ", s
                              ^^^

instead of on line 2. While an experienced programmer should be able to figure out what's wrong, I can see a beginner programmer trying to "fix" the problem like this:

print 'hello = ', hello, "; s = ", s"

and then complaining that print doesn't print.

Limiting string literals to one line limits the possibility of damage to a single line. You will still have the same problem if you missed to close triple-quoted string, but since triple-quoted string are much rarer and they're pretty eye-catching, this sort of error harder are much harder.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to