Live data from Hacker News

Falsehoods Programmers believe about Time

infiniteundo.com

211–220 of 222 posts

Re: Falsehoods Programmers believe about Time

#211
* durations and points are commensurate

points in time are relative to some fixed point, and are (more or less) dimensionless. durations are not, and are (more or less) vectors. this has a couple consequences: durations are independent of epoch, while points aren't, and only certain types of math make sense with each.

basically, the only thing you can do with two points is subtract them (yielding a duration)--the rest of arithmetic (including addition) is meaningless. the only things you can do with a point and a duration is add or subtract them (yielding a point). you can't do anything at all with a point and a dimensionless scalar. the only things you can do with two durations is add or subtract them (yielding a duration) or divide them (yielding a scalar). the only things you can do with a duration and a scalar is multiply or divide them.

(personally i'd say that even the commutative operations shouldn't necessarily be commutative--i'd say point+duration->point, but duration+point->undefined--but that may be a bit too strict.)

as a quick rule of thumb, if your code would break if you changed epochs, it's already broken.

Re: Falsehoods Programmers believe about Time

#212
post #125
post #116

Earlier quoted context omitted.

But that's a bug in Excel. "Non leap years will never contain a leap day" is true.

It was a bug in Lotus 1-2-3 that was intentionally implemented into Excel, so technically it was a backwards-compatibility "feature". And some items from the original list aren't exactly "truths" as much as implementations or configurations, e.g. > 19. The system clock will never be set to a time that is in the distant past or the far future. > 20. Time has no beginning and no end.

'items from the original list aren't exactly "truths" as much as implementations or configurations' QFT.

Re: Falsehoods Programmers believe about Time

#213

Earlier quoted context omitted.

36. Two timezones that differ will differ by an integer number of half hours. 37. Okay, quarter hours. 38. Okay, seconds, but it will be a consistent difference if we ignore DST.

39. If you create two date objects right beside each other, they'll represent the same time. (a fantastic Heisenbug generator) 40. You can wait for the clock to reach exactly HH:MM:SS by sampling once a second.

#40 actually made me laugh out loud. Bitterly, but out loud :-)

Re: Falsehoods Programmers believe about Time

#214

I was reading this and realizing that he was mixing two very different things: design considerations and design errors. Treating every year as 365 days is a design error. Leap years will break it. "Timezones next to eachother don't require changes of more than 1 hr" might also doom that F22 flying across the international date line (ok, I am assuming that was more of a test assumption than a code assumption). On the…

I could tell you some stories about not being able to expire cookies.

Re: Falsehoods Programmers believe about Time

#215
post #103

Earlier quoted context omitted.

One I caught recently: The difference between the current time and one week from the current time is not always 7 * 86400 seconds. By noticing an automated test that failed 2 weeks out of the year.

I think every test suite has tests that only fail right around the start and end of daylight savings time.

If the tests are failing because the production code is confused about daylight savings time, then you may have a serious problem.

If on the other hand it's just the test code that's flaky, usually such problems can be alleviated by refactoring such that one passes the time function as a parameter. This is in preference to hard-coding calls to the system time in test, which imho one should never do.

Once an arbitrary time function can be passed as a parameter, one can provide a mock or fake system clock for test purposes. Ideally one would still want to test under daylight savings' conditions. But at the least this approach leaves one in a place where one can test the common 24-hours-in-a-day case without having the tests spuriously fail two days out of every year.

Re: Falsehoods Programmers believe about Time

#216

From the headline, my first thought was that this was going to be about estimating development time/effort on a project.

Falsehoods we believe about estimating development time/effort:

1. For any non-trivial project, it is possible to estimate development time and/or effort with a reasonable degree of accuracy.

Re: Falsehoods Programmers believe about Time

#218
post #82

"The smallest unit of time is a milli/second" seems a bit silly, as it really depends on your application. Is he expecting programmers to implement time in Planck units?

The specific issue that bit me wrt units of time was seconds vs. milliseconds. This came up the first time I needed to mix PHP time stamps with Jenkins build log time stamps. One is in seconds, the other in milliseconds. Unfortunately the PHP date() function exhibits odd behavior when a time stamp contains two extra digits. I could have saved myself the debugging time had I not been so attached to the assumption that time stamps are always in seconds rather than sometimes in milliseconds.
Post reply on HN