PEP 285: Adding a bool type

Paul Prescod paul at prescod.net
Sun Mar 31 11:01:29 EST 2002


Arthur Siegel wrote:
> 
>...
> 
> If I am concerned about the readability of my code
> for other non-experts (and I usually am), I might
> do a:
> 
> True = 1
> False = 0
> 
> at a modules head and go from there.
> 
> I am not understanding what beyond that the
> Boolean type accomplishes.
> 
> It would perhaps not detract from the debate
> if the upside could be explained in terms that
> spoke to the practicalities of writing workable
> and readable code in Python, rather than in
> terms of language design theory and
> implementation internals.

One way to sum it up is "if that's a good convention for readability
then why not make it a built-in concept in the language so that we do
not all invent our own spellings for it?" Having bool be separate from
integer is useful for introspection. For instance if you pass a "1" to
Jython, COM or SOAP, it is hard for Jython or the Python COM bindings or
ZSI to know whether you meant to pass an integer or a boolean. In the
worse case this can mean you call the wrong overloaded method. Even in
pure python it may occasionally (very occasionally) be useful to write
code of the form: "if the first argument is a boolean then do X, else if
it is an integer do Y." Finally, booleans can have different displays so
that:

print "isWindowMaximized:", isWindowMaximized

will print "True", rather than "1". The former is a little clearer.

 Paul Prescod




More information about the Python-list mailing list