Grouping code by indentation - feature or ******?

Larry Bates lbates at syscononline.com
Fri Mar 25 17:15:54 CET 2005


Python's way of grouping is VERY good.  Over the last
30+ years I've seen a lot of code (good and bad) in
many languages.  IMHO good code (independent of language)
always uses indentation, even when other block constructs
(like braces) is available. Python developers thought that
this was redundant.  Just make the indentation mean
something and lose the block construct characters.

Secondly,  Python "nudges" me into writing better
(easier to maintain and clearer to understand) code by
influencing me towards splitting my code into smaller
functions/classes.  If I find myself with more than 3-4
levels of indentation, I probably need to move some of the
lower level code into a function or a class anyway (I
actually ran into this this very morning). Some might
interpret this as a negative, I don't.  I find that a lot
of programmers put WAY too much code into single individual
modules (main programs, functions) for their own good.  It
is harder to read, harder to understand, and harder to
maintain.  I believe that Python tends to make these
programmers better by influencing them to write more
modular code.  The best method for deeply nested grouping
is usually the introduction of functions/classes that
divide the deeply nested grouping into more manageable
and debuggable pieces.

Larry Bates







Tim Tyler wrote:
> What do you guys think about Python's grouping of code via indentation?
> 
> Is it good - perhaps because it saves space and eliminates keypresses?
> 
> Or is it bad - perhaps because it makes program flow dependent on 
> invisible, and unpronouncable characters - and results in more
> manual alignment issues by preventing code formatters from managing
> indentation?
> 
> Python is certainly pretty unorthodox in this area.
> 
> How would you have dealt with the issue of how to group statements?



More information about the Python-list mailing list