[Python-Dev] Adding a conditional expression in Py3.0 (original) (raw)
Gary Herron gherron at islandtraining.com
Wed Sep 21 17:46:47 CEST 2005
- Previous message: [Python-Dev] Adding a conditional expression in Py3.0
- Next message: [Python-Dev] Adding a conditional expression in Py3.0
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Michael Hudson wrote:
Guido van Rossum <guido at python.org> writes:
Given the later addition of generator expressions with mandatory parentheses , the mandatory-parentheses version of a conditional expression looks less strange to me than it did then ;-). So I could happily use it even though I may still lean toward the other option 2 version (then-else) due to its not needing ':'s or a third elseif term for chaining.
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 to me. But that's exactly what any language looks like if you get abstract enough:
WORD WORD WORD WORD WORD WORD WORD
And in fact, one read and understands your return statement just like an English sentence -- word by word from beginning to end. This seems an argument FOR the syntax not against. Moreover, if one uses the proposed parenthesized syntax, even the slightly odd word order of "return if" is mitigated.
return (if self.arg is None then default else self.arg)
None of the other expression forms (list comprehensions and generator expressions) involving statement keywords use colons.
This is also true. If you want general community input, I would suggest a runoff ballot with those four choices (and a summary of pros and cons of each), or fewer if you see any as unacceptible.
If there's one thing I've learned from the PEP 308 vote, it is that votes for language don't work. I prefer some discussion on Python-dev after which I pick one. Well, this is my input (and now I'm going to try and stay out of it). Cheers, mwh
- Previous message: [Python-Dev] Adding a conditional expression in Py3.0
- Next message: [Python-Dev] Adding a conditional expression in Py3.0
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]