For review: PEP 308 - If-then-else expression
Erik Max Francis
max at alcyone.com
Mon Feb 10 02:48:30 EST 2003
Andrew Koenig wrote:
> I'm proposing that the parser should decide when it sees the "if" that
> it is parsing an if-statement and rule out the possibility that it is
> parsing an expression that is also a statement.
In other words, writing
if C: x else: y
as a standalone statement (the Corner Case) is illegal. If you _really_
meant that, you should parenthesize it:
(if C: x else: y)
(which will be legal since the opening parenthesis means we already know
we're dealing with an expression) or, instead, just write it out as
if C: x
else: y
or
if C:
x
else:
y
Let's all remind ourselves that this is indeed a Corner Case. The most
popular uses of conditional operators are in assignments and in
arguments to function calls. Conditional operators in solitary
expressions as standalone statements are in my experience very rare (in
any language). Conditional operators are where you want to de-emphasize
the flow control; if they're a standalone expression then that's no
longer the case, and so use of them that way constitutes, in my opinion,
obscurity.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ No man quite believes in any other man.
\__/ H.L. Mencken
Alcyone Systems / http://www.alcyone.com/
Alcyone Systems, San Jose, California.
More information about the Python-list
mailing list