[Python-Dev] For review: PEP 285: Adding a bool type

Ka-Ping Yee ping@lfw.org
Sun, 10 Mar 2002 15:48:47 -0600 (CST)


I've been mulling over the whole Boolean issue and up till now it's
been bothering me vaguely but i haven't been able to put my finger
on it.  I think i have an idea now what's bugging me, though.

I've generated an outline summary at http://lfw.org/python/bool
if you'd like to see an overview of this thread.

In my mind, the current thinking is something like this:

    There are many false values (0, None, [], (), '', {}, instances
    that have len() = 0, and so on).  Other values are true.

    The general convention is that each type has one false value,
    and that it corresponds to a zero magnitude or an empty container.
    For types where + makes sense, usually x + <the false value> = x.

    It is often the case that integers are convenient to work with,
    so in the absence of any reason to choose any other particular
    type, people typically use 0 and 1.

This is not so bad, and not difficult to explain.

But in the new scheme, there is a "blessed" Boolean type.  Does this
make the other kinds of true and false less legitimate?  If so, then
what are we to do with them?  If not, then when is it more correct
to use Boolean values?

I guess this is really an issue of where we are going with this.
I know that right now the proposal is designed for compatibility,
but i'd like to know what eventual goal state Guido has in mind.
(Let's call this lim_{n -> inf} Python n, or Python inf for short.)

Q1. In Python inf, will "if" and "while" require a Boolean expression?

Q2. In Python inf, will "and", "or", "not" require Boolean operands?

Q3. In Python inf, will "True + 2" raise a TypeError?

If the answer to Q1 is "yes", then people won't be able to write

    if list:

any more.  Instead people will write one of these:

    if list != []:
    if len(list) != 0:
    if len(list) > 0:

which is troublesome (a) because there's more to type and read;
(b) because there are now many ways to write the same thing,
instead of one simple way; and (c) because it makes the code
less generic (the first option will fail if i replace "list"
with some container that i want to test for emptiness).

If the answer to Q1 is "no", then i don't see when people will
want to use Boolean values at all.  Booleans and integers will
remain interchangeable in many contexts, which leads to ambiguity.
When we read code, we won't be sure whether Booleans are involved
or not, and when we edit it we want to be consistent, but won't
know whether to write in the Boolean style or the 0/1 style.

Will people waste time on silly arguments about "thou shalt change
thy code to the One True/False Style, because it is the Proper Way"
vs. "but 0/1 works and it's less typing and i don't want to bother"?
Will programmers expend a bunch of effort editing their code to
work the new way -- effort that could have been better spent fixing
and improving their programs?  (Instantiate the preceding question
with programmers := Python-developers and programs := Python
standard library.)


-- ?!ng