What does "Sparse is better than dense" mean? (Python Zen)

Roy Smith roy at panix.com
Sat Jul 13 13:34:13 EDT 2002


Ian Bicking <ianb at colorstudy.com> wrote:
> One thing I wonder... would it be possible to use Emacs outline mode
> with the python mode, so that every syntactic : is a level in the
> outline? (well... I'm sure it's possible, but has anyone already done
> it?)

I wonder if, in the long run, that would be a good thing or a bad thing?

I like to have a given function small enough to see the whole thing on 
one screen (which typically means about 60 lines of code maximum).  It's 
not a hard and fast rule, but I find that if I can't see it all at one 
time, it's harder for me to understand what it's doing.

Once something gets so complex that I can't fit it on one screen, I 
start looking for ways to (buzzword alert) refactor the code.  That 
typically means finding some hunk of code which can/should logically be 
broken out as its own function.  That function, in turn, can get its own 
explanitory comments and unit tests.

My fear is that if I could just collapse the body of a compound 
statement with a single click, it would be too tempting to write huge 
monolihic functions that go on for hundreds of lines.



More information about the Python-list mailing list