Builtin function versus new syntax for PEP308 -- was Re: PEP308: Yet another syntax proposal

Gareth McCaughan Gareth.McCaughan at pobox.com
Wed Feb 12 14:19:19 EST 2003


Tim Delaney wrote:

[I'd said:]
> > What's the actual *disadvantage* of short-circuiting? Is it only that
> > if you have to short-circuit then you can't just write a new builtin
> > and be done with it?
>
>  Control flow is not explicit. As I stated on another thread (damn - I was
>  trying not to get involved in this too much ;) I have yet to read a ternary
>  which *relies* on short-circuiting without needing to think hard about it.

How does this

    name = (if user: user.get_name() else: "Nobody")

require more thought than this?

    if user:
        name = user.get_name()
    else:
        name = "Nobody"

Some thought is required, but it seems to me to be the same
in both cases.

>  Control flow should be explicit. Anything which participates in a
>  short-circuiting expression should behave identically if the
>  short-circuiting were not present. Short-circuiting should be an
>  optimisation only.
>
>  i.e. You shouldn't have side-effects in a short-circuiting expression.

I understand that you believe those things, but can you explain
why you believe them?

Do you, by the way, feel the same way about short-circuiting
"and" and "or"? Things like

    item_is_good = i>=0 and a[i].is_good()

for instance?

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
.sig under construc




More information about the Python-list mailing list