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

Opus opus at value.net
Sat Jul 13 07:37:29 EDT 2002


I like the idea of tabular format of code, and it brings back thoughts of my 
days of programming in RPG.  For anyone that has had to use it, you know what I 
mean.  For those that don't, writing code in it meant that you have a form that 
you wrote the code on, then you typed it in.  And, then you counted spaces if 
you had a bad editor, or you let the editor count them for you if you had a 
good one.  RPG needs everything to be in the correct column.

As for the nicest formated languages for reading, coding and debugging, I would 
have to say that my experience with 4Test (the language developed by Segue for 
QA Partner and Silk) was the best I have had.  It required that you use the IDE 
(you could use a text editor if you really wanted, but why?) to enter code.  
The IDE and the language supported collapsible blocks.  When you were coding, 
it automaticly indented for you, and showed a [-] next to the line to show that 
you could collapse it.  A [+] showed that you could expand it.  The IDE also 
had options to expand and collapse the current block, all sub blocks, and the 
entire file.  Because it was saved as a text file that was then checked into a 
repository, it was a company standard to collapse all blocks before checking it 
in.  

The great advantage here was that in reading the code, you could get an 
overview of lots of lines of code, and then drill into smaller chunks for more 
specific details.  For entering the code, it enforced a standard indentation, 
and like Python, you unindented to end a block.

>From the point of view of someone that has sat down to write a program with out 
a detailed spec (and from someone that knows that this happens IRL), the 
ability of a language to allow the developer to quickly see emerging patterns 
that can be broken into function calls (or macros, or what ever) will speed the 
development, debugging, and maintenance phases of code.

As to style, that is something that is best agreed upon with all that are going 
to touch any bit of code.  To choose a global style standard is a good idea 
IMHO.  To realize and modify that standard within the group of developers is 
also a good idea.  I believe that at one point some one did not like:
 
}
else {

Well, this might be a good place to warp the standard to your taste, and those 
around you, or live with it if they don't want to.

Reading code out side of one's normal style can be difficult.  To comprehend 
the code can also be difficult.  I have found that I like a certain level of 
comments, and I try to comment my code as much as possible.  But, I have seen 
where the comments were like Kudzu, you could not see the code that actually 
did the work.  Well written and understandable code is much like a well written 
book, a pleasure to read, where as badly written code is a pain.

These are just my rambling $0.02 worth.  Thought I would share them with ya.

On 13 Jul 2002 at 3:34, James J. Besemer wrote:

> 
> 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.
> 
> Regards
> 
> --jb
> 
> --
> James J. Besemer  503-280-0838 voice
> http://cascade-sys.com  503-280-0375 fax
> mailto:jb at cascade-sys.com
> 
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list


--Opus--

You can't tell me what sucks!
                            - Beavis, a true Objectivist.

--------------------------------------------------------
Get added to my Humor list:
mailto:opus at value.net?subject=ADD_HUMOR
Get added to my Neat list:
mailto:opus at value.net?subject=ADD_NEAT
Get my PGP public key:
mailto:opus at value.net?subject=PSEND&body=send%20PublicKEY.asc
Visit My Home Page:
http://value.net/~opus/








More information about the Python-list mailing list