PEP308: Yet another syntax proposal
Harvey Thomas
hst at empolis.co.uk
Mon Feb 10 11:59:48 EST 2003
Aahz wrote:
> In article <YUP1a.3080$SB2.242 at nwrddc03.gnilink.net>,
> Raymond Hettinger <python at rcn.com> wrote:
> >
> >I suggest:
> >
> > cond ?? val1 || val2
>
> +0.5
>
> I still have yet to see a clear explanation of why short-circuit is
> necessary and therefore iif() unreasonable.
> --
> Aahz (aahz at pythoncraft.com) <*>
Unless I'm missing the point completely, compare:
if cond:
x = calc(1, resource_intensive_1())
else:
x = calc(1, resource_intensive_2())
with
x = calc(1, iif(cond, resource_intensive_1(), resource_intensive_2()))
In the second case both resource_intensive_1() and resource_intensive_2()
are evaluated. There is of course the possibility of undesired side-effects.
You can warn people to not use iif for such cases, but you won't stop it being used wrongly.
_____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.
More information about the Python-list
mailing list