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

Muhammad Alkarouri malkarouri at yahoo.co.uk
Wed Mar 31 04:19:06 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. 
> 
> Jim

And is there a conflict?
When I used Delphi/Pascal, I always go for:

if true then
begin
...
end

and using C, invariably:

if (true){
..
}

After all, it's indentation, which is more or less cosmetic in these languages.

Muhammad Alkarouri



More information about the Python-list mailing list