Is using range() in for loops really Pythonic?

Carl Banks pavlovevidence at gmail.com
Mon May 12 14:23:07 EDT 2008


On May 12, 3:42 am, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:
> Because of the precedent of those names, choosing one of those names
> doesn't make it clear to the reader that the value is never used;


Why is it even necessary to document this?  This is the thing that
baffles me the most about this thread.

Think about all the various aspect of a varibale:

* is it some common usage archetype
* value it represents
* scope
* (expected) type
* physical units of measure
* software package it belongs to
* whether it's used in the program or not
* scalar, structure, or array
* mutable or constant
* and so on

You cannot possibly document all of this pertinent information in the
name alone.  A variable's name is a very limited resource: one can
only document a tiny number of things, so one must prioritize.

IMHO, whether a varibale is used or not has got to be one of the least
important things of all (in no small part because it's easily
discernable from nearby code).  In fact, I'd say it's so irrelevant I
probably wouldn't have listed it if it wasn't the topic of discussion.

The first two items I listed are the most important to me.  If a
variable fills the archetypal role of counter, then it ought to be
named like a counter; this usually trumps all other concerns.  (Never
mind that the varibale here isn't really a counter, it still fills the
archetypal role of one, which is more important.  The name of a
variable is for the reader's benefit.)  So I would have to agree with
Ivan Illarionov.

Having said that, if you do think it's most important to document
whether something is used, I would suggest not using "_" (because it's
conflicts with gettext conventions) or "dummy" (because it's
misleading) for it.


Carl Banks



More information about the Python-list mailing list