3 ms·
I love that one of the first programming exercises you do as a student is to program a leap year calculator. Most students will forget or not know that every 40
by JohnMakin 3y ago
I love that one of the first programming exercises you do as a student is to program a leap year calculator. Most students will forget or not know that every 400 years is a leap year, and I think the valuable lesson there is that even though code may seem trivially simple, it may have logical errors based on faulty assumptions that will bite you.
- munk-a 3y agoIt's a good lesson - and the really proper take-away is to reject NIH tendencies and just use something like tzdatabase or language functions - your 400 year example isn't comprehensive - there are a series of exceptions beyond the 400 year one and, the best bit, they may be revised without warning. Use a library - let someone dedicated to the problem handle it.
- garaetjjte 3y ago>there are a series of exceptions beyond the 400 year one There are none, calendar repeats every 400 years.
- munk-a 3y agoYou are incorrect because the solution to leap years is approximate - we'll need to actually remove leap days on years that are multiples of 3200 and that won't even make things perfect. Time is more complicated than you assume - and if you program this yourself be prepared to also get messed up by leap seconds which are used to account for earth's rotation varying over time.
- saalweachter 3y agoIt's hilarious to me that the ONE TIME the once-in-four-hundred-years exception mattered [well, I guess some parts of the world adopted it before 1600] is during the time period when students routinely implement leap year calculations on computers.