[Python-Dev] bool conversion wart? (original) (raw)

Jordan Greenberg jordangreenberg at gmail.com
Mon Feb 26 04:36:13 CET 2007


Guido van Rossum wrote:

How would this change be helpful? I'm utterly mystified by these suggestions that bool would be more useful if it didn't behave like an int in arithmetic.

I don't think anyones really saying it would be more useful, it obviously wouldn't, since like Greg said, it wouldn't work in mapping access or set membership like it does now. I think it would be more readable though, since thinks like this:

True in set([1]) True

or that 5+True is equal to 6 aren't necessarily obvious to someone who doesn't know that True evaluates to 1.

The fact that bool is a subclass of int is more historic than necessary. If not for Python's long usage of 0 and 1 to be the canonical False and True, I suspect that bool might have been implemented as a new standalone type.

Not necessarily. I really like the idea that bool is embedded in int, just like int is embedded in float (real), and real is embedded in complex.

It is elegant to embed bool in int, but to me it screams C. To me, it makes more sense to use an int if you want an int, and to reserve boolean for logic.

From an elegance/usefulness standpoint, maybe bool should evaluate to 0 and 1. But IMHO, it would eliminate some gotchas and improve readability if it didn't.

-Jordan Greenberg, not a Py-Dev, just an interested luser^H^H^Hrker.



More information about the Python-Dev mailing list