[Python-ideas] Implicit string literal concatenation considered harmful?
Barry Warsaw
barry at python.org
Fri May 10 21:41:16 CEST 2013
On May 10, 2013, at 09:28 PM, M.-A. Lemburg wrote:
>>> Would it be reasonable to start deprecating this and eventually remove
>>> it from the language?
I'm pretty mixed. OT1H, you're right, it's a common mistake and often *very*
hard to spot. A SyntaxWarning when it appears on a single line doesn't help
because I'm much more likely to forget a trailing comma in situations like:
files = [
'/tmp/foo',
'/etc/passwd'
'/etc/group',
'/var/cache',
]
(g'wan, spot the missing comma ;).
OTOH, doing things like:
>s = ('abc\n'
> 'def\n'
> 'ghi\n')
>t = ('some long paragraph spanning multiple lines in an editor, '
> 'without newlines')
Is pretty common in code I see all the time. I'm not sure why; I use it
occasionally, but only very rarely. A lot of folks like this style a lot
though from what I can tell.
>This looks and works much better than triple-quoted string literals,
>esp. when defining such string literals in indented code.
I also see this code a lot:
from textwrap import dedent
s = dedent("""\
abc
def
ghi
""")
I think having to deal with indentation could be a common reason why people
use implicit concatenation instead of TQS.
All things considered, I think the difficult-to-spot bugginess of implicit
concatenation outweighs the occasional convenience of it.
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130510/a1a32b9e/attachment.pgp>
More information about the Python-ideas
mailing list