Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!sun-barr!newstop!exodus!red-dwarf!pallas From: pallas@eng.sun.com (Joseph Pallas) Newsgroups: comp.object Subject: Re: Documenting OO Systems Keywords: operators Message-ID: Date: 29 Mar 91 21:47:49 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> Sender: news@exodus.Eng.Sun.COM Lines: 40 In jls@rutabaga.Rational.COM (Jim Showalter) writes: >Okay, what is this going to do?: > int j (int y, int m, int d) { > int m_d[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; > if (m<1 || m>12) return 0; > int l = !(y%4) && y&400; > if (d<1 || d>(m_d[m-1] + (m==2 && y))) return 0; > int dd = 0; > for (int i=0; i return dd + d + (m>2 && y); > } >You should be able to tell me right off the bat--you think English sucks >as a programming language, and this is DEFINITELY not written in English. I can't believe I'm about to waste my time on this, but here goes: 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; i2 && year); } I've left the name of the function cryptic, but the rest is the result of a simple global substitution. It becomes immediately apparent not only what the function is supposed to do, but that it contains at least one error (surely you meant to check (month==2 && leap)). Funny thing is, the function is still written in C. Amazing, isn't it? joe