PEP 285: Adding a bool type

Don Garrett garrett at bgb-consulting.com
Mon Apr 1 13:42:03 EST 2002


  One alternative approach does come to mind..... If there were really good
general support for enumerations, then boolean could be implmented as an
enumeration, not as it's own construct.

Guido van Rossum wrote:

>     1) Should this PEP be accepted at all.

  When I first started learning Python, I considered the lack of a Bool type a
horrible wart, and promptly added 'TRUE' 'FALSE' constants to everything I
write. Since then I've gotten over it, dropped the constants, and been
perfectly happy.

  The language doesn't NEED bool, and languages should never be amy bigger
than needed (look at Ada). However, this is a very common construct, and it's
what instructors and programmers new to the language expect. A language should
work the way you expect.

  My vote: +0
 
>     2) Should str(True) return "True" or "1": "1" might reduce
>        backwards compatibility problems, but looks strange to me.
>        (repr(True) would always return "True".)

  Return "True" and "False" in all cases. If you're going to do it, do it
right!

>     4) Should we strive to eliminate non-Boolean operations on bools
>        in the future, through suitable warnings, so that e.g. True+1
>        would eventually (e.g. in Python 3000 be illegal).  Personally,
>        I think we shouldn't; 28+isleap(y) seems totally reasonable to
>        me.

  No, I don't think they cause problems, and often make code simpler.
 
>     5) Should operator.truth(x) return an int or a bool.  Tim Peters
>        believes it should return an int because it's been documented
>        as such.  I think it should return a bool; most other standard
>        predicates (e.g. issubtype()) have also been documented as
>        returning 0 or 1, and it's obvious that we want to change those
>        to return a bool.

  Again, if you're going to do it, do it right! Everything in the libraries
(and in new code) that is a boolean value should use a boolean type.

  That documentation was correct for the old versions of Python. The
documentation should be updated for the new versions!

--
Don Garrett                             http://www.bgb.cc/garrett/
BGB Consulting                                      garrett at bgb.cc



More information about the Python-list mailing list