proper use of braces in Python

Carl Banks imbosol at aerojockey.invalid
Wed Mar 31 22:29:29 EST 2004


Paul McGuire wrote:
> 
> 
> "Michael" <mogmios at mlug.missouri.edu> wrote in message
> news:mailman.148.1080691972.20120.python-list at python.org...
>>
>> >>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.
>>
> http://c2.com/cgi/wiki/wiki?WhereDoTheBracesGo
> 
> Not having to deal with this #$*^!!@ is just about my favorite feature of
> Python!  (Although I'm not excited about getting into a thread on an issue
> that is so flame-prone.  Honestly, though. "There is no other way."?  "This
> is clearly better."?  I really interpret your stance as "This is the way I'm
> used to."  What's annoying is the added "... and therefore superior."
> implication.  The visual cues provided by brace placement are extremely
> subjective, and what is "clearly better" to one is confusing to another.)


Paul,

What you're seeing here is a couple Pythonistas mocking C and Java
programmers who take these sorts of arguments dead-seriously.  (But
not Perl programmers: they don't actually use braces. :)

Here at Python, we like to think that we argue about more important
things.  It's part of the Zen of Python: there should only be one way
to do it.  Because when there's more than one way to do it, you get
arguments like this.

"More than one way to do it" has led to the space vs. tab arguments we
have here.  As far as I'm concerned, the biggest problem with spaces
and tabs is that you can use either, i.e., there's *unnecessarily*
more than one way to do it.  And the Python Gods are rightly getting
rid of that.


-- 
CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon



More information about the Python-list mailing list