[Python-Dev] Adding a conditional expression in Py3.0

Jack Diederich jack at performancedrivers.com
Tue Sep 20 20:14:23 CEST 2005


On Tue, Sep 20, 2005 at 09:04:53AM -0700, Guido van Rossum wrote:
> On 9/20/05, Michael Hudson <mwh at python.net> wrote:
> > Guido van Rossum <guido at python.org> writes:
> > 
> > > On 9/19/05, Raymond Hettinger <raymond.hettinger at verizon.net> wrote:
> > >> I propose that in Py3.0, the "and" and "or" operators be simplified to
> > >> always return a Boolean value instead of returning the last evaluated
> > >> argument.
> > >
> > > While you're at it, maybe we should switch to && and || as well?
> > > That's another thing I always mistype when switching between
> > > languages...
> > 
> > You're joking, surely?
> 
> I wasn't, but I wasn't pushing for it either. Consider it withdrawn
> given the response.
> 
> > > Also, this proposal needs to be considered together with the addition
> > > of a proper conditional operator, like x?y:z.
> > 
> > I think this discussion has been had before, you know.
> 
> Unfortunately, if we were to accept Raymond's proposal, we'd have to
> revisit the discussion, since his proposal removes several ways we
> currently avoid the need.
> 
> In fact, I think Raymond's example is more properly considered an
> argument for adding a conditional expression than for removing the
> current behavior of the and/or shortcut operators; had we had a
> conditional expression, he wouldn't have tried to use the "x and y or
> z" syntax that bit him.
> 
> Given this realization, I'm now -1 on Raymond's idea, and +1 on adding
> a conditional expression. I believe (y if x else z) was my favorite
> last time, wasn't it? I've changed the subject accordingly.

I'm +1 for allowing authors to write
  return bool(thing or default)
when they mean a function to return a bool.  I had the "privilege" of
working in a large base of perl code (a learning experience) and while
some engineers abused functions that were documented as only returning
true/false by depending on the side effects of 'and' and 'or' this
was easily fixed.  The functions were changed to literally return
a plain true or false value and those engineers were summarily fired.

I'm a dependable Hettinger fanboy but on this one I have to agree
with the we're-all-adults club.  Let the authors type an extra few
chars if they want to make the code match the intent.

-jackdied


More information about the Python-Dev mailing list