while true: !!!

Alex Martelli aleaxit at yahoo.com
Wed Dec 20 12:54:28 CET 2000

"Greg Ewing" <greg at cosc.canterbury.ac.nz> wrote in message
news:3A4024E5.98843CFC at cosc.canterbury.ac.nz...
> Tim Hochberg wrote:
> >
> > If I attempt to summarize I get the following for false items:
> >
> > * None
> > * Anything that equals zero (Including a class instance with __nonzero__
> > returning false)
> > * An empty sequence (Including a class instance with __len__ returning
> The fact that it's taken about three attempts by
> experienced Python people to come up with a full
> and accurate characterisation of what constitute
> 'true' and 'false' in Python suggests that things
> could have been a lot simpler if there had been a
> dedicated boolean type!

I disagree that it suggests that.  There is a dedicated
int type, but charactezing accurately all expressions
that yield an integer 0 (when fed to the 'int' function)
is still a bother -- even "all _objects_ that yield an
integer 0 when fed to 'int'" takes quite a bit.

If there was a dedicated bool type, and of course a
'bool' function, it would take *exactly* as much effort
to enumerate all X's such that:
    if bool(X):
        print "bu!"
prints 'bu', as it now takes to enumerate all X's
such that the simpler:
    if X:
        print "bu!"
prints the same.  That's *IF*, of course, the precious
characteristic of polymorphism is maintained with its
current power!  Polymorphism _could_ be taken away, at
a considerable loss of power and handiness of course,
and _that_ would no doubt ease the specific task of
'listing all object that behave in this way' -- without
polymorphism, 'objects that behave in this way' are
a finite and predetermined set; WITH polymorphism,
the answer to "what objects behave in this way" always
has to be "all, and those only, which WANT to behave
in this way".  I dispute that lack of polymorphism is
'simpler', because the typical use-case is NOT that of
enumerating objects that behave in certain ways, but
rather that of _designing_ an object to behave in a
certain way (which for the boolean case translates to
'implement __nonzero__, or, missing that, __length__')
or _using_ an object you've received without worrying
WHY it chooses to behave thus and thus (and in THIS
very typical situation, polymorphism *simplifies* your
life enormously!).

So, summarizing: whether a dedicated boolean type exists
or not has no real bearing on the issue; polymorphism
does (if one was so crazy as to want to remove it, one
might perfectly well remove it without introducing a
'dedicated boolean type'), but it's an optical illusion
to thing that removing it would 'simplify' things!


More information about the Python-list mailing list