PEP 285: Adding a bool type

phil hunt philh at comuno.freeserve.co.uk
Sat Mar 30 14:53:53 EST 2002


On Sat, 30 Mar 2002 00:39:10 -0500, Guido van Rossum <guido at python.org> wrote:
>Abstract
>
>    This PEP proposes the introduction of a new built-in type, bool,
>    with two constants, False and True.

My first reaction to this was "shit, this will break every 
non-trivial program". However the details of the proposal are such 
that it won't, it goes out of its way to implement backwards 
compatibility.

>Rationale
>
>    Most languages eventually grow a Boolean type; even C99 (the new
>    and improved C standard, not yet widely adopted) has one.

That's hardly a valid reason.

Should we scrap syntactic indentation and use BEGIN and END keywords 
instead? Most languages do some varient of that.

>    Here are some arguments derived from teaching Python.  When
>    showing people comparison operators etc. in the interactive shell,
>    I think this is a bit ugly:
>
>        >>> a = 13
>        >>> b = 12
>        >>> a > b
>        1
>        >>>
>
>    If this was:
>
>        >>> a > b
>        True
>        >>>

That *is* a valid reason. However, it must be decided whether 
Python's primary goal is to be easy to learn or easy to use.

This proposal makes it easier to learn in some respects, but adds 
difficulty as well, as the user must learn a new data type, albeit 
a rather simple one.

>    it would require one millisecond less thinking each time a 0 or 1
>    was printed.

This would be true the first 2 or 3 times someone sees a 0 or 1 in 
response to a boolean query.

>    There's also the issue (which I've seen puzzling even experienced
>    Pythonistas who had been away from the language for a while) that if
>    you see:
>
>        >>> cmp(a, b)
>        1
>        >>> cmp(a, a)
>        0
>        >>> 
>
>    you might be tempted to believe that cmp() also returned a truth
>    value.  If ints are not (normally) used for Booleans results, this
>    would stand out much more clearly as something completely
>    different.

That's true, but it's not a biggy.

>    Other languages (C99, C++, Java) name the constants "false" and
>    "true", in all lowercase.  In Python, I prefer to stick with the
>    example set by the existing built-in constants, which all use
>    CapitalizedWords: None, Ellipsis, NotImplemented (as well as all
>    built-in exceptions).  Python's built-in module uses all lowercase
>    for functions and types only.  But I'm willing to consider the
>    lowercase alternatives if enough people think it looks better.

I prefer True, False.


-- 
<"><"><"> Philip Hunt <philh at comuno.freeserve.co.uk> <"><"><">
"I would guess that he really believes whatever is politically 
advantageous for him to believe." 
                        -- Alison Brooks, referring to Michael
                              Portillo, on soc.history.what-if



More information about the Python-list mailing list