Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!newcastle.ac.uk!turing!ncmh From: Chris.Holt@newcastle.ac.uk (Chris Holt) Newsgroups: comp.object Subject: Re: Documenting OO Systems Keywords: operators Message-ID: <1991Apr2.225553.13893@newcastle.ac.uk> Date: 2 Apr 91 22:55:53 GMT References: <299@orbit.gtephx.UUCP> <1991Mar25.145441.1@happy.colorado.edu> <20106@alice.att.com> <3481@engadm3.csd.mot.com> <1991Mar26.191259.14470@i88.isc.com> <4693@osc.COM> pallas@eng.sun.com (Joseph Pallas) writes: >-int j (int year, int month, int day) { >-int month_days[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; >-if (month<1 || month>12) return 0; >-int leap = !(year%4) && year&400; >-if (day<1 || day>(month_days[month-1] + (month==2 && year))) return 0; >-int dayofmonth = 0; >-for (int i=0; i-return dayofmonth + day + (month>2 && year); >-} >Having read the rest of the posts I now know what it does. Reading it with the >variables changed gave me a clue that it did something with days, months, and >years and the amount of days in a month. But not being a regular C programmer, >I still wasn't able to *quickly* figure out exactly what it was doing. I couldn't be bothered with the original version, and again having read the posts I know what it does. But *why* should it ever return 0, rather than some bottom value or exception? It seems to me we've got a language with pretty poor typing facilities :-). Arr, Jim lad; I remember when we used less than 0 for the first branch, 0 for the second, and greater than 0 for the third. That were intuitively obvious, that were. ----------------------------------------------------------------------------- Chris.Holt@newcastle.ac.uk Computing Lab, U of Newcastle upon Tyne, UK ----------------------------------------------------------------------------- "And when they die by thousands why, he laughs like anything." G Chesterton