PEP 285: Adding a bool type

Jimmy Retzlaff jimmy at retzlaff.com
Sat Mar 30 16:22:13 EST 2002


Greg Weeks wrote:
> I would, though, be happy to see built-in variables bound to 0 and 1.

I assume you mean that the only change would be to implicitly have
built-ins like:

False = 0
True = 1

There is a trap with this approach in that some people will come to
conceptualize False/True as being instances of a Boolean type, even
though they are not. Consider code like:

if MyCoolFunction(12.3) == True:
	print 'cool'

If MyCoolFunction returns a "true" value which is not 1 (e.g., -1), then
this code will not take the path suggested by the misconception that
True is an instance of a proper type (which would imply robust
implementations of comparison operators).

This trap is common in C/C++ code that #defines true and false. Some
people have to be constantly reminded not to compare to true, and those
reminders all too often come in the form of long debugging sessions.

Jimmy




More information about the Python-list mailing list