boolean true and false values.

Tony J Ibbs (Tibs) tony at lsl.co.uk
Thu Jun 22 04:28:03 EDT 2000


Thinking about whether Python should have "true" booleans, rather than its
current behaviour, Albert Hofkamp wrote:
> I read a number of replies, but didn't read an answer that seems
> satisfactory. I ran in the same problem, and was also not able
> to find a elegant solution.
> Using 0 and 1 or `true` and None is not correct imho, there
> should be a native way to use true and false for indicating
> boolean values.

When I first started using Python, I also found this to be uncomfortable.
However, that was *my* problem, not Python's!

There seem to be two (equally valid, I hasten to add!) traditions of
handling booleans in programming languages. The (arguably) most obvious is
to have a discrete boolean type, and thus the logical operators return a
result of that type, and so on. Algol based languages tend to take this
approach, and I have always found it more natural (as a pedant).

The other tradition is that used by (for instance) the various Lisp
derivatives, which is to have "empty" quantities represent false, and
everything else represent true. This has various practical benefits, and I
hesitate to argue it is less "theoretically" good.

A language designer has to choose one or the other. Language users then get
to grumble if they don't like it. But both are eminently respectable, with a
long history.

C, of course, sort-of adopts the second mechanism, but I don't actually
believe that that is other than coincidentally related to Guido's decision
in Python - *I* think he knew what he was doing and made a decision based on
history to get the behaviour he wanted.

(This explanation does not, of course, work for my pet hate in Python, which
is that 0 at the start of a number means it is in octal (does *anyone* care
about octal anymore?) - but perhaps this is Guido's homage to the Amish idea
that any construction of mankind should contain a deliberate mistake, as
only god can make something perfect. It is, of course, a very *petty* pet
hate...)

[I guess my age is showing - I find it terminally (sorry - perhaps that
should be "terribly") amusing how many people think that C or C++ is an
ur-language on which all others must be based, because it is *so old* -
almost as funny as people who think Linux (or Windows) has been around a
long time...]

Tibs, in an awkward mood, feeling grumpy at all the people who *like* C
based languages - BCPL was so much more elegant...

--
Tony J Ibbs (Tibs)      http://www.tibsnjoan.demon.co.uk/
Quilters: the one who dies with the most fabric wins
Programmers: the one who dies with the most programming languages wins?
My views! Mine! Mine! (Unless Laser-Scan ask nicely to borrow them.)





More information about the Python-list mailing list