[Python-ideas] Please reconsider the Boolean evaluation of midnight
Paul Moore
p.f.moore at gmail.com
Wed Mar 5 17:24:16 CET 2014
On 5 March 2014 15:55, 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.
Not really. I just found the particular example given to be confusing.
I tend to use boolean tests when I think of something as a yes/no type
of thing, and the variable name implies it. If the example had
referred to "event.attendees" I would probably have been fine with the
check as written. The attribute in that case could be any one of a
boolean flag, a count, or a list of attendees. That's actually a
reasonably plausible way of writing the test to allow for later
changes to the event class API. The point here is that there's more to
whether code is good than just a black and white "does it work"
question.
But we're way off topic now - I don't even have any assurance that the
OP's code is trying to test for a None sentinel and hitting a bug
because not all time values evaluate as True (but if that's *not* his
code, he really should have pointed that out by now!) All I can say is
that *if* that is what his code is, then I think that rewriting it
with an explicit test is clearer, and I'm not convinced by his
assertion that "fixing" Python is a better solution.
> 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.
Agreed, but that doesn't mean that code taking advantage of this is
never obfuscated or hard to maintain.
Paul.
PS One final point, and I'll say this one last time and then shut up.
I have no objection to making Python better. Nor do I insist that
backward compatibility should never be broken. Nor do I wish Python
were Java. Nor do I discount the issue of hard to find bugs. But
equally, I don't think Python is perfect, nor do I think that this
behaviour is ideal. I also don't think that the core developers have
infinite time, nor do I think that every wart in Python needs to be
fixed. And I trust the core developers to make the right judgements
most of the time. All anyone should infer from this discussion is that
I don't think that reopening the bug report referred to by the OP is
productive. (You may also assume from the fact that I will drop out of
this discussion now, that I no longer think that this thread is
particularly productive :-()
More information about the Python-ideas
mailing list