PEP 285: Adding a bool type

Erik Max Francis max at alcyone.com
Mon Apr 1 17:11:02 EST 2002


Stefan Schwarzer wrote:

> I would like to have bools in Python, rather than not. But only if
> bools and ints are different types, so that "True == 1" would be
> false,
> similar to that "'1' == 1" is false. And _my_ conclusion was, that I
> would rather have no bool type than a mixed-up concept in which bools
> are really ints.

Does it bother you that 1.0 == 1, or that 1L == 1?  I certainly see the
argument that a Boolean should not be an integer, but with the current
PEP -- and to have any hope of maintaining some backward compatibility
-- a bool must be a degenerate integer, and so True == 1 makes sense. 
If you consider this evil (which I don't), then it's a necessary evil. 
Some compromises must be made for the sake of backward compatibility.

I'm not sure I see the big problem, since explicit comparisons to true
are rarely useful anyway.  i.e., this is another example of code you
_can_ write, but not necessarily code you _should_.  No matter what the
language, there is always accounting for poor programmers and bad style;
Python is no exception.

Python is not even alone in this category, other languages have (what
amounts to) implicit conversion from Booleans to integers.  

> What's the point in saying "There should be a bool type to distinguish
> between truth values and integers" when this distinction is so
> shallow?

Because the purpose is for distinguishing between _intent_ and not
value.  If I have a function that returns 0, I don't know whether that's
a count, or a Boolean, or a trinary value (say, 1, 0, and -1, like cmp),
or otherwise.  If I see one that returns False, I damn sure know what's
going on.  The inclusion of Booleans allows one to write better
self-documented code, because it indicates what the programmers is
intending to do with values, not just the values.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Nationalism is an infantile sickness.
\__/ Albert Einstein
    Alcyone Systems' Daily Planet / http://www.alcyone.com/planet.html
 A new, virtual planet, every day.



More information about the Python-list mailing list