logoalt Hacker News

zestyping • today at 12:16 AM • 2 replies • view on HN

This will probably sound crazy to some of you, but I believe the introduction of the boolean type was a mistake.

Every primitive type has a null value, and the "if" statement tests for such a value. Whether a value is true or false is a property of the value. Notice that "true" and "false" are adjectives, not nouns.

That is a simple, internally consistent model with one concept of trueness.

The introduction of the boolean type made this a lot messier: it makes "if" look like type coercion, and introduces two different ways to think of boolean-ness (as an adjective or as a noun) which you must hold in your head at the same time. For example, it became possible to compare things as equal to True or False, doubling the number of ways to express a condition: "if x" and "if x == True" are now very similar, but subtly different, ways to express the same thing. The fact that we have to talk about things as "truthy" or "falsy" as if these were different from "true" and "false" is a further illustration of the mess this has created.

If we had stuck with 0 and 1, we would have avoided all this confusion. It is imperfect but simple; what we ended up with is still imperfect and needlessly complicated.


Replies

driggs • today at 7:35 AM

I still have a printed stack of Python 1.5.7 docs from when I first learned the language.

The addition of boolean `True` and `False` were a huge improvement to the language when they were finally added in 2.3.

I'm not sure why you're making things more complicated than they need to be. Test for truthiness. Conditional statements already evaluate boolean expressions, you're not adding anything explicit by writing `== True`.

tacitusarc • today at 12:58 AM

Booleans are reductionist and likely harmful, as they allow programmers to avoid thinking in terms of the test they are actually performing: is this a member of some set? If the problem is reworked like that Booleans are superfluous (this representation could be compiled to something as performant as using Booleans).

I am not sure if that perspective aligns with yours.

➕ show 1 reply