Calendar Functions (simpler lea

Fabbian G. Dufoe fgd3 at jc3b21.UUCP
Tue Sep 30 03:27:26 AEST 1986


In article <86900058 at haddock>, karl at haddock writes:
> 
> vianet!devine (Bob Devine) writes:
> >Dave Lewis writes:
> >>   if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
> >
> >While this works, it is overkill.  Unless you believe that your
> >code will make it to the year 2100, a simple test for divisibility
> >by 4 is sufficient.

It is particularly galling to see a correct algorithm criticized as
overkill when it is as simple and short as the above code segment.  There
may be a justification for writing code that only works part of the time if
the fix is costly and difficult.  However, it should be a general rule that
an algorithm which works in all cases is preferred over one that only works
in most cases.

Instead of panning someone's code because he has written it more correctly,
one should adopt the improved algorithm with gratitude.

Fabbian Dufoe
  350 Ling-A-Mor Terrace South
  St. Petersburg, Florida  33705
  813-823-2350

UUCP: ...akgua!akguc!codas!peora!ucf-cs!usfvax2!jc3b21!fgd3 



More information about the Comp.lang.c mailing list