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

Bruce Leban bruce at leapyear.org
Thu May 16 19:26:15 CEST 2013


On Thu, May 16, 2013 at 9:57 AM, Christian Tismer <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.

--- Bruce
Latest blog post: Alice's Puzzle Page http://www.vroospeak.com
Learn how hackers think: http://j.mp/gruyere-security
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130516/045c675f/attachment-0001.html>


More information about the Python-ideas mailing list