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

Jim Jewett jimjjewett at gmail.com
Fri May 17 20:23:33 CEST 2013


On Fri, May 17, 2013 at 7:41 AM, Steven D'Aprano <steve at pearwood.info> wrote:

> They clearly should be in different threads. Line continuation is orthogonal
> to string continuation. You can have string concatenation on a single line:

In theory.  In practice, the times when I'm having trouble fitting
something onto a single line *and* cannot find a good place to break
it (using parens), the problem almost always involves a string.

And the number of times I needed to concatenate two strings on the
same line (but wasn't willing to use a +) has been ... only when when
a seemingly arbitrary syntax restriction requires a literal string --
basically, when writing a docstring.

> On 17/05/13 19:32, Christian Tismer wrote:

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

> I don't understand what this sentence means.


Today, (if you're not writing a docstring) you can write

    "abcd"
    "efgh"

and it magically turns into "abcdefgh".  He proposes that -- eventually --
you would have to write

    "abcd" \
    "efgh"

so that the \ would be an explicit indicator that you were continuing
the line, and hadn't just forgotten a comma.

> -1 since there are uses for concatenating strings on a single line.

I understand "create a string demonstrating all the quoting conventions".
I don't understand why an explicit + is so bad in that case.  Nor do I
understand what would be so horrible about breaking the physical line
there.

So the only use I know about is docstrings.  And maybe that should be
fixed there, instead.

-jJ


More information about the Python-ideas mailing list