[Python-Dev] Re: PEP 285: Adding a bool type
Ka-Ping Yee
ping@lfw.org
Wed, 3 Apr 2002 10:44:01 -0600 (CST)
Andrew Koenig wrote:
> Specifically: If I want to write a function that answers a yes/no
> question, I have lots of possible ways of spelling yes (1, 2, "yes",
> and so on) and lots of possible ways of spelling no (0, {}, None,
> and so on). There isn't a single preferred way.
Fredrik Lundh wrote:
> if you study real python code, you'll find that there is.
Andrew Koenig wrote:
> I mean that the language doesn't prefer a single way,
> as opposed to programmers' conventions.
This doesn't mean anything in practice. Every yes/no function
i've encountered returns 1 for yes and 0 for no. (If it returns
something else, then it really has more to say than yes or no.)
In fact the language actually does prefer a particular way,
since x == x returns 1.
The addition of another type really does change the set of preferred
truth values from {0, 1} to {0, False, 1, True}. The typical practicing
Python programmer who wants to say "true" would have to decide -- for
each instance -- whether to say "1" or "True".
And the programmer cannot happily ignore the issue and stick to using
0 and 1, because if comparisons start to return True and False, dealing
with a mix of four truth values is unavoidable. This PEP makes me uneasy
because it causes me to see lots of extra casts in Python's future (not
to mention confused beginners).
-- ?!ng