Booleans (was Re: My .02 on PEP308 + an extra question)

Andrew Koenig ark at research.att.com
Sun Mar 2 09:31:04 EST 2003


Stephen> I'm not convinced by this. In C++, 'bool', 'true' and 'false'
Stephen> are pretty pointless. The Ada equivalents, however, are
Stephen> not. The reason being, in C++ 'true' and 'false' cast
Stephen> implicitly to/from integers.

Stephen> Given this behaviour, the keywords 'true' and 'false' are no
Stephen> more useful than library definitions such as '#define TRUE
Stephen> 1'. The weak typing due to the implicit conversion destroys
Stephen> most, if not all, benefits of a separate type.

I really don't want to get into a debate on this, so I will just
say that this issue was discussed extensively in the C++ standards
committee and mostly they didn't agree with you.

In particular, despite the disadvantages of allowing implicit
conversions to and from bool, the type has two substantial advantages:

        1) You don't have to worry about combining libraries that
           use different conventions for representing boolean types.
        2) You can overload based on it.

These two advantages -- particularly the first -- were deemed to be
sufficient by themselves to justify introducing a new type.


-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark




More information about the Python-list mailing list