For review: PEP 308 - If-then-else expression
holger krekel
pyth at devel.trillke.net
Sat Feb 8 15:49:11 EST 2003
Chris Liechti wrote:
> mis6 at pitt.edu (Michele Simionato) wrote in
> news:2259b0e2.0302080516.1c577eb2 at posting.google.com:
> > "Sean Ross" <frobozz_electric at hotmail.com> wrote in message
> > news:<5DV0a.34649$CF1.1127662 at news20.bellglobal.com>...
> >> >
> >> > The proposed syntax is as follows:
> >> >
> >> > <expression1> if <condition> else <expression2>
> >> >
> >>
> >> While I do not think this is necessary, I would like to offer an
> >> alternative syntax:
> >>
> >> <expression1> when <condition> else <expression2>
> >>
> >
> > +1 to "when". To me "if" is associated to the conditional statement, a
> > conditional expression is a conceptually different thing and needs a
> > different expression. Readability is worth adding a new keyword.
>
> +1 for 'when', +0 for 'if'
>
> i'd prefer an other word as the condition and 'then'-part is swapped,
> compared to other ifs, as statement and in listcomps.
>
> i think that the ternary operator completes listcomps and i like those.
> also i think it's nice for initialiters:
>
> class X:
> def __init__(self, optarg = None):
> self.someval = optarg when optarg is not None else default_value
>
> i think an expression is much better here than an if statement in this
> case.
If i didn't knew the quality of your postings i would think
your are kidding. I'd very much prefer
if optarg is None:
optarg = default_value
self.someval = optarg
because this is not only a common idiom (e.g. when you need
default arguments to be lists or dicts) but it also parses
(to me) in an instant. I doubt that
self.someval = optarg when optarg is not None else default_value
would ever begin to have the same 'ring' with me.
cheers,
holger
More information about the Python-list
mailing list