For review: PEP 308 - If-then-else expression
Carlos Ribeiro
cribeiro at mail.inet.com.br
Sat Feb 8 19:44:32 EST 2003
On Saturday 08 February 2003 02:51 pm, Aahz wrote:
> In article <yu998ywqdevm.fsf at europa.research.att.com>,
>
> Andrew Koenig <ark at research.att.com> wrote:
> >The real question, then, is how much stylistic diversity the Python
> >community wants to allow.
>
> Right. In general, Python has focused on mechanisms for reducing
> stylistic diversity, because that makes programs easier to read.
One more reason to support conditional expressions, because it will allow a
*single way to do it*, instead of every person coming up with a different
hack to achieve the same effect.
Today, those who want to write a simple conditional expression have three
choices:
1) using if statements, enclosed or not in a helper function;
2) using the 'a and b or c' hack, which abuses the semantics of logical
expression evaluation to give the desired result;
3) using the indexed tuple/list technique, which is fine for some problems,
but mistake-prone because it forces the programmer to reverse the order of
the 'true' and 'false' arguments (or to reverse the test condition, whatever
you like more).
Now, having *three* different idioms is better than having a single one?
Carlos Ribeiro
cribeiro at mail.inet.com.br
More information about the Python-list
mailing list