python-dev summary, July 16-31

François Pinard pinard at iro.umontreal.ca
Wed Aug 8 14:25:42 EDT 2001


> > 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 engcorp.com> wrote:

> > I would never have thought to write either of these.

Really?  You write parentheses all the time?

Whenever 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"... :-)

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.

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.

[Alex Martelli]

> I fully agree, so I just submitted a feature request to sourceforge --
> hopefully one doesn't have to write a PEP for _this_ sort of stuff?-)

Thanks a lot for the attempt.  I'm not sure how it will go.  In:

    for x in 1, 2, 3:
        pass

the `in' is nothing more than a mandated keyword.  But with:

    if x in 1, 2, 3:
        pass

the `in' is an operator, and as such, has its priority relative to a comma.
It might not be easy adjusting this without breaking anything.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Python-list mailing list