PEP308: Yet another syntax proposal
Aahz
aahz at pythoncraft.com
Mon Feb 10 12:49:29 EST 2003
In article <9pR1a.22187$F25.13842 at nwrddc02.gnilink.net>,
Raymond Hettinger <python at rcn.com> wrote:
>"Aahz" <aahz at pythoncraft.com>
>>
>> I still have yet to see a clear explanation of why short-circuit is
>> necessary and therefore iif() unreasonable.
>
>It is necessary when:
>1. One of the alternatives has a side-effect; or
>2. one or both alternatives are time consuming; or
>3. the validity of the alternatives depends on the outcome
> of the test.
>
># Example where all three reasons apply
>data = isinstance(source, str) ?? source.readlines() || source.split()
>
>1. readlines() moves the file pointer
>2. for long sources, both alternatives take time
>3. split() is only valid for strings and readlines() is only
> valid for file objects.
You're missing the point. How frequently does this occur such that
getting all our knickers in a twist is worth it? So far, most of the
examples pushing a conditional expression have *NOT* required
short-circut behavior. For the cases where side-effects restrict the
use of a conditional expression, I think perhaps requiring the use of an
if statement is the most appropriate way to handle it.
--
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