[Python-ideas] Implicit string literal concatenation considered harmful?
Steven D'Aprano
steve at pearwood.info
Fri May 17 13:41:44 CEST 2013
On 17/05/13 19:32, Christian Tismer wrote:
> 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:
>>> 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.
They clearly should be in different threads. Line continuation is orthogonal to string continuation. You can have string concatenation on a single line:
s = "Label:\t" r"Data containing \ backslashes"
And you can have line continuations not involving strings:
result = math.sin(23*theta) + cos(17*theta) - \
sin(3*theta**2)*cos(5*theta**3)
Since the two things under discussion are independent, they should be discussed in different threads.
> - implicit string concatenation becomes deprecated
-1
Implicit string concatenation is useful, and used by many people without problems.
> - the backslash will allow comments, as proposed by Bruce
+0
It's not really that important these days. If you want comments, use brackets to group a multi-line expression.
> - continuation of a string on the next line will later enforce the backslash.
I don't understand what this sentence means.
> So repeating Bruce's example, the following would be allowed:
>
> x = [ # THIS WOULD BE ALLOWED
> 'abc' \
> 'def' \ # not the python keyword
> 'ghi'
> ]
The backslashes are redundant, since the square brackets already enable a multi-line expression.
> 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.
-1 since there are uses for concatenating strings on a single line.
> 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.
I don't understand this objection, since the parentheses are being used to group an expression.
And they are being used to group expressions.
> The reason why Python has grown the recommendation to use parentheses
> comes more from the absence of a good alternative.
Maybe so, but now that we have multi-line expressions inside brackets, the need for an alternative is much reduced.
--
Steven
More information about the Python-ideas
mailing list