allow line break at operators

Chris Angelico rosuav at
Tue Aug 16 22:05:57 CEST 2011

On Tue, Aug 16, 2011 at 8:26 PM, Prasad, Ramit
<ramit.prasad at> wrote:
> I am not sure why people are so stuck on braces. I figured other people would be like me and tired of having to do things like figuring out where I missed an end brace.

I'm one of the fans of braces, but search the list archives and you'll
find plenty of arguments on both sides. I like braces because they
allow me to separate the syntax from the layout; I can choose to
indent things based on logical structure, even when that doesn't
correspond to the compiler's notion of the structure. Here's an
example from C++:

struct _blah
    int x;
    int y;
    char **z;
    //etc etc etc
    }; struct blah: public _blah {
    char padding[1024-sizeof(_blah)];

The inheritance isn't significant to the overall concept of the object
(the idea was that it should have a size of exactly 1024, as this had
to interface with some lower-level systems), but it's significant to
the compiler's understanding of the object. The braces, therefore,
follow the compiler's requirements, but the indentation follows the
programmer's. (And yes, there were comments explaining things, and
much better element names.)

Another idiom I often use in C or C++ is the "conditional for loop":

for (x=getfirst();x;x=getnext()) if (x%3)

The equivalent in Python:

for x in blah: if x%3:

is not legal, and must be written with an extra indentation:

for x in blah:
    if x%3:

I'm sure I could sort something out with a filtering generator, but it
seems ridiculous to write:

def condition(gen,func):
    for elem in gen:
        if func(elem): yield elem

for x in condition(blah,lambda x: x%3):

There are very good reasons for Python's system, and I don't object to
it *in Python*. But I do not see indentation-as-structure as the
ultimate and perfect system, and I desire and intend to preserve the
freedom to choose languages with different systems.

Chris Angelico

More information about the Python-list mailing list