[Python-ideas] Implicit string literal concatenation considered harmful?

Christian Tismer tismer at stackless.com
Thu May 16 20:07:22 CEST 2013


Hey Bruce!

On 16.05.13 19:26, Bruce Leban wrote:
>
> On Thu, May 16, 2013 at 9:57 AM, Christian Tismer 
> <tismer at stackless.com <mailto:tismer at stackless.com>> wrote:
>
>     The "&" is not a valid operator on strings and looks pretty much like
>     gluing parts together. It is better than the "\" that just escapes
>     the newline
>     and cannot take comments.
>
>
> I don't like something that is a standard operator becoming special 
> syntax. While it's true that string & string is not valid, it's not 
> the case that string & ... is not valid. I dislike dot for the same 
> reason. It's confusing that these would do different things:
>
>     'abc' & 'def'
>     ('abc') & 'def'
>
> I like the \ idea because it's clearly syntax and not an operator, but 
> the fact that it doesn't work with comments is annoying since one 
> reason to break a string is to insert comments. I don't like that 
> spaces after the \ are not allowed because trailing spaces are 
> invisible to me but not to the parser. So what if the rule for 
> trailing \ was changed to:
>
>     The \ continuation character may be followed by white space and a
>     comment. If a comment is present, there must be at least one
>     whitespace character between the \ and the comment.
>
>
> That is:
>
> x = [  # THIS WOULD BE ALLOWED
>     'abc'   \
>     'def'   \   # not the python keyword
>     'ghi'
> ]
>
> x = [  # THIS WOULD BE AN ERROR
>     'abc'   \
>     'def' # a comment but no continuation \
>     'ghi'
> ]
>
> One thing I like about using \ is that it already works (aside from my 
> proposed comment change). So anyone wanting to write 
> forward/backward-compatible code can just add the \s now. If you want 
> to start enforcing the restriction, just use from __future__ import 
> explicit_string_continuation.

Right, that's a good one!
Although I hate the backslash from bad experience with windows.
But actually the most reason that I always hated to use "\" for continuation
lines is its strict behavior that does not allow any white space after it.

Hey, it would be great if that proposal makes it !

cheers - chris

-- 
Christian Tismer             :^)   <mailto:tismer at stackless.com>
Software Consulting          :     Have a break! Take a ride on Python's
Karl-Liebknecht-Str. 121     :    *Starship* http://starship.python.net/
14482 Potsdam                :     PGP key -> http://pgp.uni-mainz.de
phone +49 173 24 18 776  fax +49 (30) 700143-0023
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
       whom do you want to sponsor today?   http://www.stackless.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130516/4911a8e3/attachment.html>


More information about the Python-ideas mailing list