Here's a test that will highlight the problem:
Dim dob = #6/2/1979# Dim dt = #6/1/2009# ' day before 30th b-day Assert.AreEqual(Util.Age(dob, dt), 29) ' WORKS! dob = #6/2/1978# ' Lets use 1978 now... Dim dt = #6/1/2008# ' day before 30th b-day Assert.AreEqual(Util.Age(dob, dt), 29) ' FAILS! WHAT!?
What happened here? The second method, the one I argued yesterday was terse and still readable and therefore better has a bug in it on leap years. Let me state Matt's axioms of programming 101 -
- All significant code has bugs.
- If you think your code is bug free, see axiom #1
- Code that looks bad has obvious bugs
- Code that looks elegant still has bugs, but you're less likely to see them