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

Christian Tismer tismer at stackless.com
Fri May 17 11:32:41 CEST 2013


On 16.05.13 20:20, Chris Angelico wrote:
> On Fri, May 17, 2013 at 4:14 AM, Bruce Leban <bruce at leapyear.org> wrote:
>> On Thu, May 16, 2013 at 10:38 AM, MRAB <python at mrabarnett.plus.com> wrote:
>>> Why do you say """there must be at least one whitespace character
>>> between the \ and the comment"""?
>>
>> Two reasons:
>>
>> (1) make the backslash more likely to stand out visually (and we can't
>> require a space before it)
>>
>> (2) \# looks like it might be an escape sequence of some sort while I don't
>> think \ # does, making this friendlier to readers.
>>
>> I'm not passionate about that detail if the rest of the proposal flies.
> Spin that off as a separate thread, I think the change to the
> backslash rules stands alone. I would support it; allowing a
> line-continuation backslash to be followed by a comment is a Good
> Thing imo.
>

I don't think these matters should be discussed in separate threads.

We came from Guido's proposal to remove implicit string concatenation.
In that context, some people argued that there should be no new
".", "&" or whatever operator rules, but better handling of the unbeloved
backslash.

I think both can and should be treated together.
Doing so, I come to repeat this proposal:

- implicit string concatenation becomes deprecated

- the backslash will allow comments, as proposed by Bruce

- continuation of a string on the next line will later enforce the 
backslash.

So repeating Bruce's example, the following would be allowed:

x = [  # THIS WOULD BE ALLOWED
     'abc'   \
     'def'   \   # not the python keyword
     'ghi'
]

And this would be an error:

x = [  # THIS WOULD BE AN ERROR
     'abc'   \
     'def'   # a comment but no continuation \
     'ghi'
]

'\' would become kind of a line glue operator that becomes
needed to merge the strings.

I don't think that parentheses are superior for that.
Parentheses are for expressions and they suggest expressions.
Avoiding parentheses where they don't group parts of expressions
is imo a good thing.
The reason why Python has grown the recommendation to use parentheses
comes more from the absence of a good alternative.

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/



More information about the Python-ideas mailing list