[Python-ideas] Implicit string literal concatenation considered harmful?
Stephen J. Turnbull
stephen at xemacs.org
Sun May 12 02:30:04 CEST 2013
Mark Janssen writes:
> > > I think that is an awesome idea.
> >
> > Violates TOOWTDI.
> >
> > >>> print("This is an" + # traditional explicit operator
> > ... " %s idea." % ("awesome" if False else "unimpressive"))
> > This is an unimpressive idea.
> > >>>
>
> But you see you just helped me demonstrate my point: the Python
> interpreter *itself* uses ... as a line-continuation operater!
No, it doesn't. It's a (physical) line *separator* there. This:
>>> "This is a syntax" +
File "<stdin>", line 1
"this is a syntax " +
^
SyntaxError: invalid syntax
>>>
is a syntax error. If "... " were a line continuation, it would
be a prompt for the rest of the line, but you never get there.
> Also, it won't violate TOOWTDI if the "+" operator is deprecated for
> strings. Strings are different from numbers anyway, it's an old
> habit/wart to use "+" for them.
They're both just mathematical objects that have operations defined on
them. Although in math we usually express multiplication by
juxtaposition, I personally think EIBTI applies here. Ie, IMO using
"+" makes a lot of sense although the precedence argument is a good
one (but not good enough for introducing another operator, especially
using a symbol that already has a different syntactic meaning).
I think it's pretty clear that deprecating compile-time concatenation
by juxtaposition would be massively unpopular, so the deprecation
should be delayed until there's a truly attractive alternative.
I think the various proposals for a dedenting syntax come close, but
there remains too much resistance for my taste, and I suspect Guido
won't push it. I also agree with those who think that it probably
should wait for Python 4, given that it was apparently considered and
rejected for Python 3.
More information about the Python-ideas
mailing list