For review: PEP 308 - If-then-else expression
sross at connectmail.carleton.ca
Sat Feb 8 20:57:01 CET 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:
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
x if C else y
And, as someone posted, you can always use
if (x if C else y):
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 126.96.36.199...
> 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