[Python-ideas] Line continuations with comments

Bruce Leban bruce at leapyear.org
Wed May 22 18:02:16 CEST 2013


On Wed, May 22, 2013 at 6:41 AM, Mike Graham <mikegraham at gmail.com> wrote:

> Backslash line continuations are mostly to be avoided and making a change
> like this would seem to
>
> a. make them slightly less obvious when they are used,
> b. increase their use in cases where there aren't even long lines of code
> involved, and
> c. seem to encourage their use in general.
>
> It seems to me that using parentheses is an already-existing,
> somewhat-better way to do what you're doing in your examples.
>
>
Your last statement seems to be missing the point of the larger discussion.
Yes, parenthesis can be used in most cases where someone might use \
continuation. There seems to be strong sentiment to *not* remove \
continuation. Given that, is allowing comments after a continuation a
reasonable change? I think so.

Notwithstanding that, these discussions are moving away from Guido's
original comment about being bitten by implicit continuation of strings and
not moving towards consensus. Let me throw in a few facts:

1) There are bugs caused by unintended implicit string concatenation.
2) Using + as it exists now is not a drop-in replacement for implicit
string concatenation as it is a run-time operation and has a different
precedence than the implicit concatenation.
3) There are programs that use implicit string concatenation that will need
to be fixed if the feature is removed.
4) There are programs that use \ continuation that will need to be fixed if
the feature is removed.
5) Explicit is better than implicit.

Personally, I would endorse deprecating and eventually removing implicit
string concatenation and adding a syntax (not an operator) for explicit
run-time string concatenation. The use of \ continuation as that syntax
seems to me like a reasonable choice if we assume that this feature isn't
going away. In particular, it works today so it's easy to start using it
and linters can look for it. However, it's pointless to bikeshed the choice
of syntax if there's no consensus that there should be an explicit syntax
in the first place.


On Tue, May 21, 2013 at 9:13 PM, Ron Adam <ron3200 at gmail.com> wrote:

> I was able to make a small patch that removed the some of the restrictions
> on the '\' for testing some ideas which does the following.
>
>     * Allow a line to continue on the same line.
>
>
Aside from serving as a marker for explicit string concatenation, this
means that I can freely sprinkle in backslashes anywhere I want, like this:

    foo \ = \ bar + \ \ 3

That seems like a bad idea.


> <snip>
>
> The reason \# works, but not \ #, is when the comment comes directly after
> the back slash, it's removed and leaves a (backslash + new-line) pair.
>

Whether we require there be no space between \ and # or, conversely,
require there be at least one whitespace character should not be based on
the relative ease of patching the current code. Personally, I would prefer
the latter as I believe requiring a space after \ will increase readability.


--- 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/20130522/8e621e8f/attachment.html>


More information about the Python-ideas mailing list