[Python-ideas] Implicit string literal concatenation considered harmful?
Andrew Barnert
abarnert at yahoo.com
Thu May 16 04:54:10 CEST 2013
On May 15, 2013, at 19:24, Cameron Simpson <cs at zip.com.au> wrote:
> I much prefer:
> + 'foo'
> over
> c'foo'
I agree, but this doesn't solve the precedence problem that everyone keeps bringing up.
Summarizing (more in hopes that someone will correct me if I've missed something important than to help you or anyone else...):
Implicit concatenation is bad because you often use it accidentally when you intended a comma.
A rule only allowing implicit concatenation on separate lines doesn't help because both legit and accidental uses are usually on separate lines.
There's no way a compiler or linter could help, because there's no programmatic way to distinguish good from bad uses:
log("long log message with {} "
"and {}",
"one arg"
"and another")
Using + doesn't work because of operator precedence vs. % and .:
print("long log message with {} " +
"and {}".format("one arg", "and another"))
Using an explicit dedent or similar method call doesn't work because the performance is unacceptable.
Automatically optimizing the dedent call at compile time doesn't work because sometimes you need it to be at run time.
Assuming all of those givens are true, it seems inescapable that either we need some new syntax, or we have to just accept the problem.
More information about the Python-ideas
mailing list