[Python-Dev] Adding a conditional expression in Py3.0 (original) (raw)

BJörn Lindqvist bjourne at gmail.com
Wed Sep 21 18:56:14 CEST 2005


> I think I'd prefer (if then else ) i.e. no > colons.

My problem with this syntax is that it can be hard to read: return if self.arg is None then default else self.arg looks worryingly like return NAME NAME.NAME NAME NAME NAME NAME NAME NAME.NAME

That can already be written in Python:

return self.arg or default

And maybe the syntax of the future conditional operator could be extended so that:

return self.arg else default

Would be equivalent to the previous line. For stuff were a conditional expression really is needed, like in:

return if self.arg then "yes" else "no"

One would hope that whoever writes the conditional expression doesn't make the expressions so long and complicated that it looks like NAME NAME.NAME NAME... It doesn't matter which syntax proposal that wins, it will still be very tempting to write unreadable code with it (think nested/chained conditional expressions). That (and the fact that I've never felt a real need for a conditional expression thanks to the "or" operator) is my very humble argument against it.

-- mvh Björn



More information about the Python-Dev mailing list