[Python-ideas] allow line break at operators

Yingjie Lan lanyjie at yahoo.com
Sat Sep 3 09:51:11 CEST 2011

I agree that long lines of code are not very common in many projects, though it might be the case with some heavily involved in math. For some reason, when the feature of free line breaking came about in computer languages, it is welcomed and generally well accepted. Python uses indentation for blocks, and by the same mechanism, line breaking can be accommodated without requiring parenthesis or ending backslashes.

For the tuning, yes, people would disagree on how to split expressions/code. The continue-by-indentation would allow people to break a line in whatever way that pleases their aesthetic taste, as long as there is an indentation. Most people seems to like an indentation on the continuing lines, probably for a visual indication of a continuation line. Some general guidelines may be provided, but there is no need for other hard rules on breaking lines, except that an identifier should never be split apart.

For the implementation, I don't have much clue. At least on the parser, it needs to look beyond the linefeed to determine if a line is completed. If the indentation is defined as a single symbol, then it would only require a one-step look-ahead, and that should not be hard.

Again, my apology for top posting.

>From: Stephen J. Turnbull <stephen at xemacs.org>
>To: Yingjie Lan <lanyjie at yahoo.com>
>Cc: Gabriel AHTUNE <gahtune at gmail.com>; Matt Joiner <anacrolix at gmail.com>; "python-list at python.org" <python-list at python.org>; python-ideas <python-ideas at python.org>
>Sent: Saturday, September 3, 2011 2:10 PM
>Subject: Re: [Python-ideas] allow line break at operators
>Yingjie Lan writes:
>> Have you considered line continuation by indentation? It seems to
>> meet the design principle. I think it is the most natural way to
>> allow free line breaking in Python.
>Briefly, yes, and I think it would need a lot of tuning and probably
>complex rules.  Unlike statements, where everybody (except the judges
>of the Obfuscated C Contest) agrees on a simple rule: "In a control
>structure, the controlled suite should be uniformly indented one
>level", line breaking and indentation of long expressions is an art,
>and people have different opinions on "readability" and "beauty."
>Achieving a compromise that is workable even for a few major styles is
>likely to be annoying and bug-prone.
>Pretty much every program I write seems to have a continued list of
>data or a multi-line dictionary display as data.  It's not unusual for
>me to comment the formal arguments in a function definition, or the
>parent classes of a class definition.  The exception for parenthesized
>objects is something I depend on for what I consider good style.  Of
>course I could use explicit continuation, but in a long table that's
>ugly and error-prone.
>Long expressions that need to be broken across lines, on the other
>hand, often indication that I haven't thought carefully enough about
>that component of the program, and an extra pair of parentheses or a
>terminal backslash just isn't that "heavy" or ugly in the context of
>such long expressions.  For me, they're also pretty rare; many
>programs I write have no explicit continuations in them at all.
>YMMV, of course, but I find the compromise that Python arrived at to
>be very useful, and I must suppose that it was substantially easier to
>implement than "fully free" line breaking (whatever that means to you).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110903/6b108bcc/attachment.html>

More information about the Python-list mailing list