January 21, 2004

A Y2.1K Problem

Precision Blogging has an interesting entry today about commenting your code. I tried to add a comment of my own, but his comments server was down. My comment would have been, more or less, this:

Real programmers don't comment. If it was hard to write, it should be hard to understand.

Seriously, though... back in 1988 I was writing some code for a time/date display where we were only allowed two digits for the year (still in the era before anybody cared about Y2K). We didn't care about the first two digits anyway, until I found out that although 2000 would be a leap year, 2100 would NOT be, which would throw all the day-of-month and day-of-week calculations off. So I added a comment something like this:

/* Under the Rule of 100, the year 2100 is not a leap year. Under the Rule of 400, the year 2000 is. This code is written to work in the latter case and fail in the former. If this aircraft is still flying in the year 2100, I will personally return from the dead to fix the code. */

The Government reviewer was amused; my boss, somewhat less so.

Posted by Chris at January 21, 2004 06:57 PM

Category: The Day Job