PEP 285: Adding a bool type: yes, but not as int subtype

Kris J. Zaragoza kzaragoza at attbi.com
Mon Apr 1 13:33:14 EST 2002


In article <3CA79401.CFA41B65 at python.org>, Guido van Rossum wrote:
> But see also my comments on these two in
> http://www.python.org/doc/essays/pepparade.html; neither PEP is likely to
> have any effect on Python's future.
> 
> --Guido van Rossum (home page: http://www.python.org/~guido/)

Guido,

I have to ask one question that I haven't seen brought up yet: What
does PEP 285 imply for the future of Python?  Do you intend to
eventually change the concept of what is true?

Specifically, I refer to the Python Language Reference
(http://www.python.org/doc/2.2/ref/lambda.html):

"""In the context of Boolean operations, and also when expressions are
used by control flow statements, the following values are interpreted
as false: None, numeric zero of all types, empty sequences (strings,
tuples and lists), and empty mappings (dictionaries). All other values
are interpreted as true."""

Do you intend to eventually (NOTE: I say eventually, I know it's not
immediate) modify this to read that only the value True is true and
the value False is false?  If this is the case, I believe this adds
needless complexity to code whereas (in a simple case)

if foo:
    ...do whatever...

would now have to read

if bool(foo):
    ...do whatever...

in order to convert None, empty sequences/mappings, and non-integer
zeros to boolean values.  It may seem like a small change, but it
would add unnecessary verbiage to what is already fairly obvious in
control constructs and other boolean expressions.

If you don't intend to modify this concept, then what's the real gain
for the new boolean type?  The concept is already fairly clear, and
would be needlessly muddied by this extra type that holds one of two
values.  (Try explaining to a newbie that it's actually one of two
pre-allocated instances!)

The only real advantage I can see in the latter case is to make some
code a bit more self-documenting.  If you assign a value of False or
True to a variable, it's pretty clear what that variable is intended
to hold.  However, given the firestorm of discussion that has erupted
around the details of this PEP, is this small gain really worth the
effort?  Is there some other advantage I'm missing?

Kris

--
Kris J. Zaragoza       | On the face of it, Microsoft complaining about
kzaragoza at attbi.com    | the source license used by Linux is like the
                       | event horizon calling the kettle black.
                       | -- Adam Barr, article on kuro5hin.org




More information about the Python-list mailing list