For review: PEP 308 - If-then-else expression
Roy Smith
roy at panix.com
Sat Feb 8 00:05:28 EST 2003
Erik Max Francis <max at alcyone.com> wrote:
> That's exactly my view, as well. I would prefer `if p then x else y',
> but if an extra keyword is absolutely contradindicated, then I'll settle
> for `x if p else y'. I just want the functionality, I can learn to use
> the syntax.
If "There's more than one way to do it" is a bad philosophy, then
"There's more than one meaning for something" is equally bad. What is
"if"? Is it a conditional statement or operator in an expression?
Conditional statements drive execution of code, operators return values.
With this proposal, "if" becomes a little of both.
For the person trying to learn something new (i.e. programming), the big
hurdle is being able to generalize. If a given keyword has a dual life
(sometimes it's a statement, sometimes it's an operator), it's difficult
to make generalizations.
Or worse, you make the wrong generalization. If I can write "x = y if y
> x else x" then way can't I do the same thing with other statement keywords? Perhaps I can write "myModule = import foo" as well?
No? Why not? Why does "if" have a dual role, but not the other
keywords?
More information about the Python-list
mailing list