Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

James Coglan recently pointed out that all of Python's falsy values are the additive identity of some type. Midnight fits the mold.

This results in some weird results from an intuitive perspective, but is very principled and elegant in other ways.

My one objection was that I don't know how None fits in.



Midnight is not the addittive identity of points in time. There is no additive identity because there is no addition operation. You're confusing the ``time`` type, with the ``timedelta`` type, which represents a duration, and does have 0-minutes as an additive identity.

midnight is not, nor has it ever been, the "zero-time", it's simply a point whose typical representation contains some 0s. It is no more Falsey than the origin (0, 0) in the cartesian coordinate system is Falsey.


You win: I was confusing those things! I was thinking times were treated as a timedelta ranging from 0 to 23 hours 59...


How is "midnight" an additive identity? It's not a time delta. "+0 hours" is an additive identity. (And if Python's time library doesn't distinguish between absolute and relative times, that's a design flaw.)

That's like saying "north" is an additive identity on a compass. It's not; "+0° clockwise" is an additive identity.


To take it from the same James Coglan -> "You can't add midnight to 3-o'clock in the same way you can't add London to Chicago."


As far as I understand from reading that whole thread, this is, ironically, precisely why local midnight evaluates to False. They left in an escape hatch to support the illogical idea of addition.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: