[Python-ideas] allow line break at operators

Stephen J. Turnbull stephen at xemacs.org
Sat Sep 3 02:10:26 EDT 2011

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).

More information about the Python-list mailing list