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

Steven D'Aprano steve at pearwood.info
Thu Mar 6 04:00:02 CET 2014


On Wed, Mar 05, 2014 at 09:23:37PM -0500, Donald Stufft wrote:

> It’s hard to do any sort of search for this, however in an informal poll where I’ve shown
> people this code not a single person thought it made sense, and most of them responded
> with “wtf?”.

Well I don't know who these people are, what their background is, or 
exactly how you phrased the question. But in my experience, most 
programmers have extremely strongly held opinions about the sensibility 
of certain features that have little or nothing with any rational 
analysis of the pros and cons and far more likely to be "that's 
different from the first language I learned, therefore it's rubbish".

Having read Tim's explanation for why time() is falsey, I no longer 
think it's a misfeature, and am now -0.5 on changing it at all.


> I’ve also seen first hand through Django (which is why the person who 
> started this thread) get caught by this bug and have to spend hours 
> trying to figure out why it’s behaving that way.

Again, I don't know the background here, and we all know that sometimes 
tracking down bugs can be difficult, but if somebody is spending "hours" 
trying to debug why "if time_value" sometimes does the wrong thing, 
*without* bothering to read the documentation for time objects to find 
out how they're supposed to behave, then I don't have a lot of sympathy.

Also, if you write "if spam" as a short-cut for "if spam is not None", 
then again any bugs you experience are self-inflicted.


-- 
Steven


More information about the Python-ideas mailing list