For review: PEP 308 - If-then-else expression

Gerrit Holl gerrit at nl.linux.org
Fri Feb 7 15:22:15 EST 2003


Guido van Rossum schreef op vrijdag  7 februari om 18:16:27 +0000:
>         x if C else y if D else z <==> x if C else (y if D else z)

Does this equal the following?

if C: x
elif D: y
else: z

>         x or y if C else z        <==> (x or y) if C else z
> 	      x if C else y or z        <==> x if C else (y or z)
>         lambda: x if C else y     <==> lambda: (x if C else y)
>         x if C else lambda: y     <==> SyntaxError
>         x if C else y, z          <==> (x if C else y), z
>         x, y if C else z          <==> x, (y if C else z)

I really oppose this one.
IMHO, if-else clauses should never be expressions.
IMHO, this is bad for readability.
IMHO, it is not explicit.
IMHO, it's not useful.
IMHO, it unnecceraly enlarges the language.
IMHO, it's perlish.
IMHO, it's hard to understand.
IMHO, conditions should be before resulting expressions.
IMHO, we do not need this at all.
IMHO, since else is obliged, 'x if a' is not allowed but 'x if a else None'
is, which is not intuitive.

-1

>         <condition> ? <expression1> : <expression2>

>     I reject this for several reasons: the colon already has many uses
>     in Python (even though it would actually not be ambiguous, because
>     the question mark requires a matching colon); for people not used
>     to C-derived language, it is hard to understand.

I would prefer this one to the 'x-if-a-else-b'-variant, but would
still vote -1. I disagree that it's hard to understand for people
not used to a C-derived language, at least it is not true for me
(and Python was my first serious language). But we don't need it.

>         if <condition> then <expression1> else <expression2>

Argh, no. Then sucks. -1

For what it's worth.

yours,
Gerrit.

-- 
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list