PEP 285: Adding a bool type

John Roth johnroth at ameritech.net
Sun Apr 7 10:04:15 EDT 2002


"David Eppstein" <eppstein at ics.uci.edu> wrote in message
news:eppstein-8A20F8.18322106042002 at news.service.uci.edu...
> In article <uavbgcabvl642b at news.supernews.com>,
>  "John Roth" <johnroth at ameritech.net> wrote:
>
> > Here I thought that teaching about bools was quite easy.
> > Bools answer a specific question: is it x? True or False.
> > They do not answer the question: which X is it?
> >
> > In other words, bools select one possible case out of
> > however many there are; they are not a substitute for a
> > universe which has only two cases.
>
> By the way, this is conceptually very similar to ints (at least,
> nonnegative ints): ints answer a specific question: how many things?
> They do not answer the question: which things are they.

Not exactly. Consider the common case of 'take a number'
played at various burocracies. The manager can tell how many
there are by inspecting the next number on the roll, but each person
waiting has his own number, and they can be called out of order.

In other words, ints do allow you to tag each case with a
specific identifier. However, you can do that with any other
type that has enough distinguishable values: I prefer strings for
debugging purposes. If I was really an OO purist, I might prefer
using the object itself, and dispensing with having to identify
it!

To take it to an extreme, I consider using an int as a proxy
for cases to be a code smell! Unless, of course, you need
them for some other reason, like indexing an array.

We might notice that Unix, for example, defines a list of
errors, indexed by small integers. Python returns an error
object, which is much more useful.

John Roth







More information about the Python-list mailing list