View Single Post
Kickaha
Veteran Member
 
Join Date: May 2004
 
2009-10-04, 23:38

Quote:
Originally Posted by Partial View Post
Do you think this is a good practice for clean code? I'm not familiar with Python but from what I'm gathering it uses indentation to determine which "if" the "else" corresponds to in your example?
Yup. No brackets at all, *just* indentation as the determining factor for block edges. Pretty elegant, and it makes it damned near foolproof to figure out what goes with what... *except*...

Quote:
Originally Posted by Banana
I fell in love when I learned about how Python handles whitespaces! What's to hate?!?
When you're dealing with a text file where one person's editor inserts tabs, one inserts 4 spaces instead of tabs, one inserts 2 spaces instead of tabs, etc, etc, etc... it falls apart. If you have a standardized whitespace creation methodology across your editors and IDEs, then it works beautifully.

But getting developers to agree on whitespace is like getting them to agree on bracket placement. If you can enforce it for a group, however, it works very well and bugs like the one before are basically impossible.

I've been known to go bracketless in one case, and even then I feel wrong doing it: where the statement fits on the same line as the if:

Code:
if (foo) bar;
But if it needs to be below the if, then it needs brackets, every time.
  quote