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

cribeiro at mail.inet.com.br cribeiro at mail.inet.com.br
Sat Feb 8 04:48:02 CET 2003


> On Fri, Feb 07, 2003 at 07:15:06PM -0600, Ian Bicking wrote:
>> if x:
>>     val = y
>> else:
>>     val = z
>>
>> And I *hate* it.
>
>   Try this one on for size:
>
>     val = z
>     if x:
>         val = y

Oh well. I just gave up discussing short-circuiting evaluation and there
we go again. The two blocks of code are not equivalent; change z for an
expression with some side effect (for example, a function call), and then
the results will be completely different.

DISCLAIMER: I'm not saying that short-circuiting is better. I'm saying
that the ternary operator uses short-circuiting evaluation *by
definition*. I'm aware that short-circuiting may lead to some weird
programming practices, and that it is not recommended by some people.

Enough said.


Carlos Ribeiro
cribeiro at mail.inet.com.br







More information about the Python-list mailing list