[Python-Dev] For review: PEP 285: Adding a bool type

M.-A. Lemburg mal@lemburg.com
Fri, 08 Mar 2002 20:31:17 +0100


Guido van Rossum wrote:
> 
> > That's the main argument for adding a boolean *type* to
> > the language. We already have the singletons...
> 
> In C, not in Python!

Sure we do:

	True = (1==1)
	False = (1==0)

and many other modules and methods return these two 
singletons as well, so it's not like you are adding 
something new to the language :-)
 
> > mxODBC in SQL binding mode. Some databases only allow
> > passing in strings, so mxODBC has to call str(obj) to
> > pass the object stringified to the database.
> >
> > This works just fine with Py_True and Py_False, since DBs
> > know that 1 and 0 are true and false. I'm not sure how
> > well 'True' and 'False' would work here, ODBC doesn't say
> > anything on these values if used in the C API, in fact
> > it doesn't have a native BOOLEAN type, just a BIT.
> 
> OK, so you may have to change one line in one module.

Nope. I'll have to add a new handler which detects the
bool type and converts it to 1 or 0 resp.

The effort required to do this is not the argument,
it's the fact that you are trying to break working code 
without any real life need. The PEP doesn't mention a
single example where the advantage is so obvious that
it requires breaking code.
 
> > Perhaps you could clarify the need for these new
> > __str__ and __repr__ values ?!
> >
> > I'd be happy with repr(True) giving me 'True',
> > but not str(True).
> 
> It just seems to make more sense if booleans print as True and False.
> But if that really is going to be the only place where things break,
> I'm willing to reconsider this.

Good.
 
> > No. The point is that printing truth values up to now has
> > always resulted in '0' or '1'. You are about to change that
> > to 'True' and 'False'. This can create a l10n issue in
> > existing applications.
> 
> An application that prints the digits 0 or 1 to mean true or false
> doesn't sound very user-friendly to me either.  I'm not worried that
> we'll get actual complaints from people that this broke their program.

The problem is that the boolean output may not have been 
intended by the programmer. All he ever got was the integers
1 and 0 -- it was never obvious to the pure Python programmer
that these two values were acutally the singletons
Py_True and Py_False. Now you want to add additional
semantics to those and things will look different on output.

> > It may also cause applications which write out boolean
> > data this way to fail, e.g. report generation tools,
> > XML generators, database extraction tools, etc...
> > Just think of code like this:
> >
> >       print '<boolean value="%s">' % (x != 0)
> >
> > (It's not like I'm running out of arguments :-)
> 
> We'll see. :-)

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/