[Python-ideas] Break the dominance of boolean values in boolean context

Guido van Rossum guido at python.org
Tue Sep 13 18:04:03 CEST 2011


On Tue, Sep 13, 2011 at 7:01 AM, Lukas Lueg <lukas.lueg at googlemail.com> wrote:
> The question is if we want to treat bools more special than any other
> type. Right now bools are the only place where this is done. Do we
> really want to specialize the language in order to favour control flow
> in the implementation? Forever? That's a bold statement.

I have no problem with this statement and don't see it as particularly
bold or controversial. Control flow just *is* special. FWIW It is not
bool values that are being treated special; it is certain bool
operators (not, and, or). I see nothing wrong with that; you can think
of them as an extension of the repertoire of 'if', 'while' etc.

> Performance is always an argument. Python as a language, and most
> especially CPython itself, has a history of favouring design over
> application; the same should be true for bools. Concerning De Morgan's
> Law, I think in Python this should be treated as a convention in the
> implementation, not a rule of the language. After all, we also have
> [1,2,3] + [4,5,6] = [1,2,3,4,5,6] not by rule but by simple reasoning.

De Morgan's law (and similar transformation) seem to me out of scope.
The would violate gut feelings about the "natural" execution order of
Python expressions.

> Also: If an object does not override a certain boolean operation, the
> compiler can still take advantage of optimisation. Progress on the AST
> may pave the road for that.

No, because the compiler does not have the runtime types of the object
available.

If you don't know how Python really works you shouldn't be making
language change proposals.

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list