PEP 285: Adding a bool type
Erno Kuusela
erno-news at erno.iki.fi
Sun Mar 31 11:59:04 EST 2002
In article <mailman.1017466974.6751.python-list at python.org>, Guido van
Rossum <guido at python.org> writes:
[...]
| 1) Should this PEP be accepted at all.
no.
[...]
| Rationale
| Most languages eventually grow a Boolean type; even C99 (the new
| and improved C standard, not yet widely adopted) has one.
i don't agree wit this argument.
| Many programmers apparently feel the need for a Boolean type; most
| Python documentation contains a bit of an apology for the absence
| of a Boolean type. I've seen lots of modules that defined
| constants "False=0" and "True=1" (or similar) at the top and used
| those. The problem with this is that everybody does it
| differently. For example, should you use "FALSE", "false",
| "False", "F" or even "f"? And should false be the value zero or
| None, or perhaps a truth value of a different type that will print
| as "true" or "false"? Adding a standard bool type to the language
| resolves those issues.
clearly you should not use constants, but use 0 and 1. i've
personally not seen any code that uses constants like that.
i'm sure you could find many other questionable practices used
by many modules. i don't agree with this argument either.
| Some external libraries (like databases and RPC packages) need to
| be able to distinguish between Boolean and integral values, and
| while it's usually possible to craft a solution, it would be
| easier if the language offered a standard Boolean type.
this is true, but not very significant.
| The standard bool type can also serve as a way to force a value to
| be interpreted as a Boolean, which can be used to normalize
| Boolean values. Writing bool(x) is much clearer than "not not x"
| and much more concise than
| if x:
| return 1
| else:
| return 0
i say add a bool() builtin that returns 0 or 1, if it makes you
feel better.
| Here are some arguments derived from teaching Python.
[...]
in my experience, even absolute beginners naturally understand
that 0 means false and 1 means true.
the fact that other objects are interpreted as true or false can be
slightly confusing, but in my opinion this is not enough of a problem
to warrant the addition to language basics.
keep python clean! ;)
-- erno
More information about the Python-list
mailing list