PEP308: Yet another syntax proposal

Dave Brueck dave at pythonapocrypha.com
Mon Feb 10 15:25:00 EST 2003


On Mon, 10 Feb 2003, Aahz wrote:

> In article <mailman.1044897041.3120.python-list at python.org>,
> Dave Brueck  <dave at pythonapocrypha.com> wrote:
> >On Mon, 10 Feb 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
> >
> >Short-circuit evaluation is never "necessary" in _any_ language - it's
> >just very, very useful sometimes. Python's 'and' operator doesn't _have_
> >to be a short-circuit operator, but it's far more useful because it is.
>
> "Far more useful", eh?  You need to argue that, not just claim it.

Why should 'and' and 'or' compound expressions be short-circuited but not
'if' expressions? It should be short-circuiting for consistency's sake,
not to mention being more useful.

If the functionality can be exactly emulated with a function, then the
utility of the new feature pretty much drops to zero (and my vote would
swing from +1 to -1). The very fact that people _don't_ just write a
little function (something far easier and less time consuming than, say,
arguing in favor of this PEP) is at least some indication that it's judged
to be worthwhile, even if how worthwhile can't be quanitifed with hard
numbers, or even if it's not very worthwhile to you.

Also, the usefulness of short-circuiting has been shown in several
realistic examples already, so there's little point in repeating them
again and again - to _you_ they just don't seem important or you're simply
ignoring them. For example, early on Michael Chermside gave one example,
you gave a broken counter-example, and Tim corrected you, but point of
Michael's example was still valid even though you never continued the
thread (it was a case where you want to call a method of an object but you
have to check for None first).

To _me_ it is important because I have run into and continue to run into
this same scenario and I find that, without a conditional operator, the
language is getting in the way because the code I have to _write_ doesn't
synch up very well with what I _mean_ (because what I mean is more
accurately conveyed by a conditional expression).

-Dave





More information about the Python-list mailing list