[Python-ideas] Please reconsider the Boolean evaluation of midnight

Chris Angelico rosuav at gmail.com
Wed Mar 5 17:26:09 CET 2014


On Thu, Mar 6, 2014 at 2:55 AM, Ryan Hiebert <ryan at ryanhiebert.com> wrote:
> I suspect you'd like the whole idea of empty collections and zeroes
> evaluating false to go away, to force this kind of style (one right way to
> do it and all). Some languages do that. Python isn't one of them.
>
> I can see both sides, but I like how Python can use empty lists and zeros as
> false values, and I often (but not always) write code that takes advantage
> of it.

The broad concept is: A thing is true, a non-thing is false. The
question is, though, which things are actually non-things? Since
Python doesn't have a concept of not storing anything into a variable,
there has to be a thing that represents the state of not being a
thing, so None should be false. Python's made the choice that an empty
string is a non-thing, but other languages choose instead to have a
separate "Nil" value and all strings are true. Same with lists,
tuples, etc. Pike's choice is that the integer 0 is false, and
anything else is true, so you distinguish between having a string and
not-having a string, rather than between having a non-empty string and
having an empty string. Simple design choice, and one that each
language follows consistently.

But if you truly want to abolish the confusion, you want REXX. In
REXX, 0 is false and 1 is true, and everything else is error 34,
"Logical value not 0 or 1". Is that really an improvement? Not in my
opinion.

ChrisA


More information about the Python-ideas mailing list