[comp.object] Ugly C Code

dmg@ssc-vax.uucp (David M Geary) (04/04/91)

In article <jls.670567351@rutabaga+ jls@rutabaga.Rational.COM (Jim Showalter) 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<month-1; i++) dayofmonth += month_days[i];
++return dayofmonth + day + (month+2 && year);
++}
+
+THIS is readable? I think the problem is more deeply rooted in the
+C culture than I thought... (this would garner one of my Ada students
+a D minus)

  The code above should garner the poster an F.

+
+P.S. For all those who said what this function does is calculate
+     the Julian date: wrong. What it is SUPPOSED to do is calculate
+     the Julian date. What it actually does is produce erroneous
+     results.

 P.S. For the poster who said that the above code produces erroneous
      results: wrong.  The code above will produce nothing since it
      will not compile.  The code above is not valid C.  Maybe
      before one posts an article to enlighten the world about how
      unreadable C is, one should *learn* C before doing so.

+     This might have been easier to see if it had been written better.

 No kidding.  What's the point?  *Anyone* can write unreadable code
 in *any* language.

jls@rutabaga.Rational.COM (Jim Showalter) (04/05/91)

> P.S. For the poster who said that the above code produces erroneous
>      results: wrong.  The code above will produce nothing since it
>      will not compile.  The code above is not valid C.  Maybe
>      before one posts an article to enlighten the world about how
>      unreadable C is, one should *learn* C before doing so.

It's C++. Maybe YOU should bone up.

> No kidding.  What's the point?  *Anyone* can write unreadable code
> in *any* language.

Read the other 98 posts on this topic. I'm tired of rehashing the same
points.
--
* The opinions expressed herein are my own, except in the realm of software *
* engineering, in which case I borrowed them from incredibly smart people.  *
*                                                                           *
* Rational: cutting-edge software engineering technology and services.      *