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

Aahz aahz at pythoncraft.com
Sat Feb 8 20:17:16 EST 2003


In article <mailman.1044751698.29131.python-list at python.org>,
Carlos Ribeiro  <cribeiro at mail.inet.com.br> wrote:
>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?

I think it's been demonstrated that many of the cases in which someone
might casually use a conditional expression might be better suited to an
existing Pythonic idiom.  So given that those techniques already exist,
it's up to you to demonstrate that the number of cases in which
conditional expressions are markedly superior is high enough to warrant
adding it to the language.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Register for PyCon now!  http://www.python.org/pycon/reg.html




More information about the Python-list mailing list