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

Janto Dreijer janto_d at hotmail.com
Sat Feb 8 18:08:12 EST 2003


Skip Montanaro <skip at pobox.com> wrote in message news:<mailman.1044649999.21853.python-list at python.org>...
> Geoff> What about ifelse(condition, then clause[, else clause])? 
> 
> In every discussion of a ternary operator this sort of suggestion comes up.
> The problem with a new builtin is that all arguments must be evaluated
> before the function is called.  This prevents the short-circuit behavior
> that is so useful in many instances.
> 
> I've updated PEP 308 to reflect this.
> 
> Skip

I find it difficult to imagine a situation where the short-circuit
behavior actually matters. Theoretically an ifelse function doesn't do
the same thing, but practically it does: Whenever I've used ternary
ops there weren't any side effects to evaluating both arguments.
Neither any performance ones.

Can someone give me a real world example of its usefulness?

Janto




More information about the Python-list mailing list