| Store | Cart

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

From: James J. Besemer <j...@cascade-sys.com>
Sat, 13 Jul 2002 03:34:44 -0700
Donn Cave wrote:

> We can say "follow the standard", or we can say "follow the standard> unless you have some other idea."

In merely advocating flexibility on minor points in the standard.  I am in no way
advocating total anarchy as you suggest in this rhetorical statement.  I think
rather you are the one advocating the extreme view.  If you hadn't said "to the
letter" and furthermore objected to Mr. Corns perfectly reasonable suggestion in
your previous post, I probably would not have taken exception.

Furthermore, we're talking about a sub-heading marked "pet peeves", which I read
as one of the more advisory parts of the standard, something you follow more or
less closely depending on how much you want to emulate a particular individual.
It's not a vital part of the standard.

Browsing through the 2.2 Library, about half the modules I checked exhibited
deviations from the standard re horizontal whitespace.  So not too many key
contributors appear to share your zealous view on this particular point.

> If you have a good way for people> to tell the difference between their own personal idiosyncrasies and> a really good idea that really deserves to be an exception, that> would be interesting.

Well, you're asking for an algorithm which anyone would be hard pressed to
provide.  I guess that makes the question rhetorical.  Howver, I am prepared to
defend tabular organization of code.

Tabular data is such a common paradigm in computers and in printed reports
precisely because it is a tremendous aid to comprehension.  In programming, first
off, you are clued in that the corresponding section of code is highly
repetitious.  Second, you are shown that each repeated part may be logically
divided into parallel pieces with similar roles.  Most importantly, a tabular
format tells you at a glance those code fragments that are common among all the
various cases, those that are common only among a subset and those that are unique
in each case.  Finally, it just looks neater.  I don't see how you can argue that
to jumble the stuff all together (thereby eliminating these choice visual cues)
makes tables or highly parallel code EASIER to read.

In my experience, code comprehension takes place at two levels.  At the higher
level, humans perceive pages or "paragraphs" at a time.  This is why proper
indentation is to vitally important.  The left whitespace and the leading keywords
give you a lot of information about the overall structure of the program without
having to read each line.  It helps you navigate the code and provides a context
for local changes.  Tables are another aid to comprehension at the higher level.

At a lower level, you zoom into individual statements, comprehend and edit them.

> Once a coding style has> really become standard, deviations from it will tend to be less readable> for most of the people who are used to that standard, and it makes no> difference if the deviations are in principle superior.

In this PEP 8 itself seems to contradict you by saying one explicit reason for
breaking the rules is:

   (1) When applying the rule would make the code less readable, even
          for someone who is used to reading code that follows the rules.

Even if you still disagree about tabular formatting specifically, the express
directive here seems to be to NOT compromise the principle of readability in favor
of standards as you suggest.

PEP8 covers vitally important major issues (like indentation) and it covers lesser
issues down to the level of horizontal whitespace (beyond tab stops), which
frankly I've NEVER seen in a coding standard.  Nevertheless, I even agree with a
lot of THOSE details, e.g., spaces around assignments and after commas.

I think your point is perfectly valid about the big issues, particularly those
that affect comprehension at the higher level.  But it breaks down when it comes
to some of the nitty details, which I bet most users can't exactly recall.  I
leave that trivia to the Hobgoblins.

> By the way, speaking of style - you may not have noticed that you> formatted your post to 84 columns.  75 or less would be nice.  I> reformatted for you.

According to my Preferences settings, Netscape is supposed to wrap outgoing
messages to 66 columns.  Like a lot of free software it doesn't always do the
right thing.   Dunno where the 84 came from, probably the listmanager.

On the plus side, Netscape wraps lines on incoming messages to my window width,
which is great.  So I don't ever find myself in the position of complaining to
others about what amounts to a limitation of my own tools.



James J. Besemer  503-280-0838 voice
http://cascade-sys.com  503-280-0375 fax
mailto:jb at cascade-sys.com

Recent Messages in this Thread
Alex Martelli Jul 11, 2002 02:28 pm
Martijn Faassen Jul 11, 2002 04:54 pm
Alex Martelli Jul 11, 2002 08:28 pm
Donn Cave Jul 11, 2002 09:17 pm
James J. Besemer Jul 12, 2002 05:43 am
Eddie Corns Jul 12, 2002 02:40 pm
Donn Cave Jul 12, 2002 05:18 pm
James J. Besemer Jul 13, 2002 06:01 am
Donn Cave Jul 13, 2002 07:26 am
James J. Besemer Jul 13, 2002 10:34 am
Michael Hudson Jul 15, 2002 02:47 pm
Aahz Jul 13, 2002 03:28 pm
Alex Martelli Jul 12, 2002 07:33 am
James J. Besemer Jul 12, 2002 08:33 am
Messages in this thread