proper use of braces in Python (was: Prothon Prototypes vs Python Classes)

John Roth newsgroups at jhrothjr.com
Wed Mar 31 08:05:34 EST 2004


"Jim Benson" <jbenson at sextans.lowell.edu> wrote in message
news:mailman.152.1080695131.20120.python-list at python.org...
> On Tue, 30 Mar 2004, Michael wrote:
>
> >
> > >>Right.  Then we can have "does the brace go on the same line or the
> > >>next line" wars.
> > >>
> > >>
> > >
> > >    int main (void)
> > >    {
> > >        if (true)
> > >        {
> > >        }
> > >
> > >        return 0;
> > >    }
> > >
> > >There is no other way.
> > >
> > >
> > No way, that wastes an entire line of code with a single brace!
> >
> > int main ( void ) {
> >     if ( true ) {
> >         return 1;
> >     }
> >     return 0;
> > }
> >
> > This is clearly better. Compact yet easy to read. I try formatting my
> > Python code exactly like this and it always complains about my braces..
> > clearly wrong.
> >
> >
>
> Hi,
>
> ...just a food for thought from a Python list lurker.
> I have always been a strong adherent to the
>
> if (true) {
>
> }
>
> form. Not too long ago on this list (i think it was),
> someone pointed out that you never see:
>
> If (true) BEGIN:
>
> END
>
> humm...i thought, your right, in that case i guess
> i would probably write the BEGIN on a different
> line...not sure what indention of the END
> i would choose.

You don't need the BEGIN. Seriously. This is one
of the things Metz got right in Ruby: except for one
special case, the compiler can tell when you start
a block -- as long as your language doesn't special
case such things as empty blocks and single statements
that, somehow, aren't blocks.

You do need the semantic equivalent of END, though.
Whether that's indentation or a keyword is a language
issue.

The special case is, of course, the literal block where
the syntax allows a function reference. That does need
to be distinguished somehow.

John Roth



> Jim
>
>
>





More information about the Python-list mailing list