Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18131

Re: Possible bug in string handling (with kludgy work-around)

From Lie Ryan <lie.1296@gmail.com>
Subject Re: Possible bug in string handling (with kludgy work-around)
Date 2011-12-29 04:54 +1100
References (1 earlier) <4ef91afb$0$29973$c3e8da3$5496439d@news.astraweb.com> <mailman.4133.1324997611.27778.python-list@python.org> <cce5eb97-8e7f-48c6-8f0d-ec6442871196@k28g2000yqn.googlegroups.com> <mailman.4155.1325021956.27778.python-list@python.org> <b67bf3de-05ad-4aec-9e0c-63ddc398f2a1@p13g2000yqd.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4187.1325094872.27778.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Possible bug in string handling (with kludgy work-around) Charles Hixson <charleshixsn@earthlink.net> - 2011-12-26 14:23 -0800
  Re: Possible bug in string handling (with kludgy work-around) Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-26 14:48 -0800
    Re: Possible bug in string handling (with kludgy work-around) Chris Angelico <rosuav@gmail.com> - 2011-12-27 10:05 +1100
  Re: Possible bug in string handling (with kludgy work-around) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-27 01:10 +0000
    Re: Possible bug in string handling (with kludgy work-around) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-12-27 09:53 -0500
      Re: Possible bug in string handling (with kludgy work-around) Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-27 10:04 -0800
        Re: Possible bug in string handling (with kludgy work-around) Lie Ryan <lie.1296@gmail.com> - 2011-12-28 08:23 +1100
        Re: Possible bug in string handling (with kludgy work-around) Terry Reedy <tjreedy@udel.edu> - 2011-12-27 16:38 -0500
          Re: Possible bug in string handling (with kludgy work-around) Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-27 16:57 -0800
            Re: Possible bug in string handling (with kludgy work-around) Lie Ryan <lie.1296@gmail.com> - 2011-12-29 04:54 +1100
        Re: Possible bug in string handling (with kludgy work-around) Terry Reedy <tjreedy@udel.edu> - 2011-12-27 16:38 -0500

csiph-web