naming convention for scalars, lists, dictionaries ...

Jack Diederich jack at performancedrivers.com
Mon Feb 28 16:06:14 EST 2005


On Mon, Feb 28, 2005 at 09:41:37PM +0100, Just wrote:
> In article <mailman.3152.1109622405.22381.python-list at python.org>,
>  Jack Diederich <jack at performancedrivers.com> wrote:
> 
> > On Mon, Feb 28, 2005 at 04:02:37PM -0500, Benji York wrote:
> > > Jack Diederich wrote:
> > > >Ditto for me, plural implies list and singular implies instance, 
> > > >for (contact) in contacts:
> > > >   # do something with contact
> > > 
> > > May I ask why you place the parenthesis in the for statement?
> > 
> > I like the tuple-ness feel of it and frequently unpack multiple
> > values in for loops.  I also like the visual feel, it makes it
> > easy to see what is being unpacked and what is the source.
> > 
> > "for (one, two, three) in somelist:"
> > versus
> > "for one, two, three in sometlist:"
> > 
> > Even with a colorizing editor (emacs) I find the first version
> > easier to read.  YMMV.
> 
> But you're using it for _single_ values. That's like writing
> 
>       (val) = someFunction(...)

Your Milage May^H^H^HDoes Vary *wink*
A quick grep of my source shows zero unparenthesized for loops,
266 with multiple unpacks and 492 iterating over single values.
Actually a bit closer to even, 96 are 'for (i) in range(len(l)):'
that were written before enumerate() came about.

I just always use parenthesis in for loops and when creating/upacking
tuples.  I find it easier to read, except in the '(var) = func()' case.
Other people never use them. *shrug* I find this impossible to get
worked up about.  What other people do in the privacy of their own
codebase doesn't bother me one bit.

My $0.01 bits,

-Jack



More information about the Python-list mailing list