For review: PEP 308 - If-then-else expression
Sean Ross
sross at connectmail.carleton.ca
Sat Feb 8 14:57:01 EST 2003
>From updated PEP308:
> Another variant proposes to use 'when' instead of 'if':
>
> <expression1> when <condition> else <expression2>
>
> I don't see the advantage of 'when' over 'if'; it adds a new
> keyword which is a major extra hurdle to introduce this. I think
> that using a different keyword suggests that the semantics are
> different than those of an 'if' statement; but they really aren't
> (only the syntax is different).
It would appear that adding a new keyword is a problem: "major extra
hurdle", to be precise. There _really_ aren't any semantic differences, per
se. I just thought it would help distinguish between if expressions and if
statements and it would eliminate the possibility of
if x if C else y:
pass
But, it looks like x if C else y will cause fewer problems to
implement, and besides its not that difficult to tell the difference between
if C:
x
else:
y
and
x if C else y
And, as someone posted, you can always use
if (x if C else y):
pass
So, I think I'll just give the 'when' advocacy a rest...
(I do still prefer it, though... ;D )
"Chris Liechti" <cliechti at gmx.net> wrote in message
news:Xns931CD07B75144cliechtigmxnet at 62.2.16.82...
> as for the new keyword 'when', i don't see a problem. the new syntax isn't
> backwards compatible anyway, so that a new keyword does not make a
> differece for backwards compatibility.
>
More information about the Python-list
mailing list