Falsehoods Programmers Believe About Time (2012)
I got two I noticed over the years:<p>* Didn&#x27;t think about time at all.<p>In most cases most don&#x27;t think about time until it becomes a problem. It often ends up with a system which behaves in surprising ways, and is the equivalent to the developer believing any of those things in the article. But there is a difference in them believing those falsehoods, and simply not being a aware of them at all.<p>* Time moves forward<p>This is probably the biggest gotcha of all. Just imagine how many times int the past you did dt = now() - t0, then did something with dt like sleep(dt). Well time will move backwards sometimes and dt is negative. I bet this will make most people here worried and they&#x27;ll think about code they wrote like that (sure did). I have seen systems freeze for example because they end up sleeping for a huge amount of time (negative number was cast to an unsigned huge number).<p>A small advice on how to improve errors related to time is to abstract it away from algorithms and code as much as possible. Instead of always calling gettimeofday() &#x2F; time() &#x2F; now() function to get the current time, in a piece of lower level code, try to pass it in as an argument. That will make code testable.<p>I have seen fun failing test cases. Something like encoding the current time the test was written and a dt to current time. The test was working for years then started failing eventually because of the hard coded time.