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

I think what he was saying was: * You should use + only for operations that form an abelian group across the domain * In those cases, it makes sense for the identity to be false.

The truth is, time doesn't have a sensible addition/combination operator, never mind an identity and inverse, so it isn't even a group.



Okay, I definitely buy that. It makes sense to add a duration (timedelta in Python) to a time, but not to add times to one another.

This is venturing off topic, but if you really wanted to, you could define addition for times in terms of timedeltas. It makes sense to subtract times and get a timedelta, so you could define addition as the subtraction with signed times and signed timedeltas. So, since `time(today) - time(yesterday) = timedelta(1 day)`, we could say that `time(today) + time(yesterday) = -timedelta(1 day)` and `time(today) - -time(yesterday) = timedelta(1 day)`. It's a bit strange to define the notion of a signed time object, but it could work.




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

Search: