python-dev summary, July 16-31

Peter Hansen peter at
Thu Aug 9 02:05:48 CEST 2001

François Pinard wrote:
> > > François Pinard wrote:
> > > > About that one, it always saddened me a little bit that I may not write:
> > > >
> > > >         if x in 1, 2, 3:
> > > >             pass
> > > >
> > > > while I can write:
> > > >
> > > >         for x in 1, 2, 3:
> > > >             pass
> > "Peter Hansen" <peter at> wrote:
> > > I would never have thought to write either of these.
> Really?  You write parentheses all the time?

No, just when I write tuples!  <wink>

Yes, I *definitely* use parentheses around tuples all the time.

 (a) One obvious way to do things.

 (b) I never knew there was another way at first, and the habit stuck.

 (c) Fits my brain better, since I see parentheses and think "tuple".
     (My brain has to pause, perhaps, when a function with arguments 
      is called.  I don't notice the pause, apparently. :-)

> Whichever language I use, I try to avoid abusing parentheses, as using them
> often leaves me with the bad feeling I do not know the language enough,
> and that I write it fuzzily, adding parentheses "just in case"... :-)

 (d) I heavily abuse parentheses for complex expressions, since I'm
     a programmer of very little brain (ref. Winnie the Pooh).
     I almost never rely on my recollection of operator precedence.
     Since this has nothing to do with tuples, I wouldn't consider
     using parentheses for tuples to be "abusive" in any way, just
     a syntax which, for me, might as well be required.

> Of course, for many languages, parentheses could be effectively used to
> increase legibility.  But for marking tuples, Python does not need them
> in most cases, it may be more noisy than useful having them to mark tuples
> when it is not required to do so.  Python sources are cleaner without such
> spurious parentheses, and it is a good habit learning to avoid them.

You haven't convinced me yet, other than the "slightly less noise" 
argument.  Other than that one debatable advantage (which may not
outweigh the associated disadvantages, to me), do you have any
other reasons you think it's a good habit to avoid this?

> There is one case, however, where using parentheses with tuples is worth
> doing, and this is for long lists of tuple elements spanning more than one
> line.  Parentheses combined with proper indenting help the eye at catching
> the overall structure.  For short tuples that fit on a line, parentheses are
> overkill to me.

For me, this paragraph leads me conclusively back to my current view:
use parentheses for all tuples.  

To do otherwise would be inconsistent, and to me 

   (inconsistency == unmaintainability) .

Peter Hansen, P.Eng.
peter at

More information about the Python-list mailing list