List Comprehension Syntax

Peter Hansen peter at engcorp.com
Mon Jul 12 10:19:14 EDT 2004


François Pinard wrote:

> ... for me at least, the greatest virtue of Python is that one can
> write it legibly, and maintainability mainly results from legibility.

I don't find the legibility of the carefully aligned version of
that code to be higher than the simpler "indent the standard amount"
version of the code.  Sometimes consistency is not foolish.

As for maintainability, the problem is not that other people
use an editor which makes it harder to produce the same level
of legibility (since I find the legibility the same or worse
with the "artistic" alignment).  The problem is that other people
who use another editor (and it should be very clear that there
are such people and will always be) will find it much harder to
maintain alignment which, without editor support, requires
careful manual alignment.

> Being easier or harder to maintain with this or that editor is rather
> irrelevant, if legibility is at stake.  A lot of people are using lesser
> editors anyway, and do all their alignment "by hand".

If they do the alignment that way, making things carefully line
up with the parentheses, and manually, they are definitely wasting
their time, IMHO, because there is NO increase in legibility.  I
used to do that... same as how I used to waste time lining up the
equals signs in initialization sections of my code.  (Now the
only place I do such things is in sections where series of related
constants are assigned, since only there does it really produce
increased readability).

In a lot of ways, this is probably the same argument as that against
using TABs.  People who like TABs most often seem to like them
because they feel TABs make it easier to tune things to their own
particular (more aesthetically pleasing) indentation standards.

In fact, since they are gaining arguably nothing (for example,
there are arguments that could be made about four spaces being
the optimal size, if we wanted to go there), but are making
maintenance harder for others, it's a net negative in the greater
scheme of things, though perhaps easier on themselves at
least in the short term.

(Wow... a simultaneous segue into both the tab war and the editor
wars! I think I'd better leave now...)

-Peter



More information about the Python-list mailing list