For review: PEP 308 - If-then-else expression
Roy Smith
roy at panix.com
Sat Feb 8 18:49:43 EST 2003
Erik Max Francis <max at alcyone.com> wrote:
> if cond:
> statement1
> else:
> statement2
>
> and collapsing it into an expression:
>
> (if cond: expression1 else: expression2)
>
> That really doesn't strike me as so bad. Particularly if most of the
> objections center around overloading the meaning of if, or the
> awkwardness of reading the proposed x if p else y structure not reading
> left-to-right, maybe this makes sense after all?
It seems to me we're getting very close to "let's take some arbitrary
code and turn it into an expression", which is essentially what a lambda
is. I'm not particularly fond of lambdas, but given that we have them,
I don't really see the point of having two versions of them.
I guess deep down, my real objection to all this is that it blurs the
line between statements and expressions. In some languages (lisp, for
example) there is no such distinction, and everything returns a value.
But in Python, there is a distinction. So is "if" a statement or an
expression? With this PEP, the answer becomes, "it depends", which I
think is a bad answer.
More information about the Python-list
mailing list