PEP 308: some candidate uses cases from live code
Tony Lownds
tony-clpy at lownds.com
Mon Feb 10 14:25:34 EST 2003
Andrew Koenig <ark at research.att.com> wrote in message news:<yu99r8agka9w.fsf at europa.research.att.com>...
> I'd prefer
>
> sy = d0.month < 7? d0.year - 1: d0.year
>
> despite duplicating d0.year because I would rather duplicate
> d0.year than subtract 0 from it. But it's not a strong preference.
>
Yes, that is a nice way of writing the expression.
> Tony> For me, that a killer problem of PEP308's proposed syntax; with the
> Tony> condition in the middle, reading *and* refactoring the code becomes
> Tony> harder! That is why I cannot vote simply for PEP308.
>
> Tony> The only syntaxes I'd like to see are:
>
> Tony> condition "?" then-expr ":" else-expr
>
> Tony> condition "?" then-expr "else" else-expr
>
> Why not
>
> "if" condition: then-expr "else" ":" else-expr
>
> ?
At first glance, I think C's syntax is more concise, consistent, and
does not confuse statements and expressions. Python's current idioms
for conditional expressions can be improved upon a bit, and IMO the ?:
syntax is an improvement. I'm not sure about the very statement-like
syntax above. At least it is in the right order! Is it even parsable?
Can you imagine explaining why this is good syntax:
if x: print y
else: print z
And this isn't:
if x: print x else: print y
-Tony Lownds
More information about the Python-list
mailing list