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

Alex Martelli aleax at aleax.it
Thu Jul 11 16:28:44 EDT 2002


Martijn Faassen wrote:

> Alex Martelli <aleax at aleax.it> wrote:
> [snip long discourse on holy war topic]
>> I suspect we'll have (at best) to agree to disagree on the
>> specifics of this.
> 
> Yes, this is probably Python's version of the "where do I put the { and
> } holy war", as you haven't managed to convince me at all; I prefer
> linebreaks after ':' and indentation for blocks, no matter how small they
> may be. My eyes do trip over the other variety and leave me with a feeling
> of frustration.
> 
> The other Python holy war topic is tabs versus spaces.
> 
> More than one way to do it can lead to holy wars, apparently. :)

Fortunately, on the tab vs spaces issue we do have the BDFL's own
word in PEP 8 -- the holy war is over, and spaces have won (quite
interesting, particularly considering that it shows Guido *can*
change his mind on such subjects).  Irreducible tab lovers can now
go form their heretical underground and plot the Tab Revolution.

No such official pronouncement for now on whether linebreak must always
come right after a colon (though I suspect I know where the BDFL's
sympathies lie on this, he hasn't gotten around to writing them down,
AFAIK, and surely not in PEP 8 so far -- good, gives us heretics-to-be
more time to prepare _our_ underground network...).

Interestingly, both cases can at least in part be framed as "there's
more than one way _and you should choose among them advisedly_" vs
"there's more than one way _but you should only ever use one of them_".

I'm on the "choose advisedly" meta-side when the way the program
looks is concerned -- and so is Guido, on some aspects (PEP 8 says
to use or not use spaces around some operators "advisedly") but not
on others (PEP 8 forbids spaces used for aligning assignments, e.g.).

I'm _definitely_ on the "use only one way" where the same looks can
be arrived at in separate ways -- where the "one way" is the one
that survives the many weird ways different programs (printer drivers,
email and news, web browsers ... it's not JUST about editors:-) can
choose to mangle tabs.  As I said, Guido agrees in PEP 8.

Interestingly enough, I find I can live with everything that is
mandated in PEP 8 -- some recommendations are not my favorite ones,
but there's nothing really major in it that irks me.  In several
ways I've consciously adapted my Python style to consistently
follow PEP 8 when it was otherwise wavering between different
usages without any strong preference.  It's _very_ different for
PEP 7, on C code style, where there _are_ a couple of points that
would make me reject a lucrative job offer if part of the
conditions was that I had to follow that style for a long time --
and I'd bet that most experienced C'ers find some aspect there
on which they feel just as strongly, though quite likely on
different subjects and opposite directions from mine...:-).


Alex






More information about the Python-list mailing list