a style question

Richard Minner rtm at christmas.UUCP
Thu Oct 25 13:21:01 AEST 1990


In article <1990Oct23.160116.10299 at athena.mit.edu> tada at athena.mit.edu (Michael J Zehr) writes:
>[stuff about printer makes i's and 1's look similar]
>This happened to a friend once:
>int a[height][width];
>for(i=0; i<height; i++)
>  for(j=0; j<width; j++) 
>    v = (a[i-1][j-1] + a[i][j-1] + a[i-1][j+i] +
>         a[i-1][j] + a[i][j] + a[i-1][j+1] +
>         a[i-1][j+1] + a[i][j-1] + a[i-1][j+1])/9;
>
>y'all see the mistake at the end of line the 4th line immediately,
>right?

This brings up something that still amazes me.  I'd have written
the broken portion above as:

    v = (a[i-1][j-1] + a[i][j-1] + a[i-1][j+i] +
         a[i-1][j  ] + a[i][j  ] + a[i-1][j+1] +
         a[i-1][j+1] + a[i][j-1] + a[i-1][j+1])/9;

in which case I would indeed immediately see all that is wrong with it.
(Lot's, it appears, even ignoring that a[i-1] doesn't exists for i == 0,
etc.  BTW, actually I would have written it right the first time.)

(As to printers that make i's and 1's look alike, all I can say is
stop using them ;-)  Who prints code anyway? >-)  Hmmm, I've seen
code that starts its indices at `j' instead of `i'.  Maybe that's
why... but I digress.)

My question is why is so little of the code I've seen `neat' in
appearance?  I have this anal tendency to line things up as
much as possible, and otherwise neaten the code.  To me, it makes
similarities and differences stand out so much better.  Sometimes
I'll even try a few different layouts and pick the one that seems
clearest (sick, I know).  I've even spotted errors in foreign code
after realigning it to get a better look.

I really am just curious why this seems to be so uncommon.  First, is
it really uncommon, or have I just missed this big pool of neat code
out there?  Or do I just have a lower `complexity/tangle threshold'
than most people? Is it just not worth the trouble?  Is vi too hard
to use?-)  Is it because `indent' and the like just mess it all up
anyway?  Do others actually find aligned code *harder* to read?  (I
suppose it's possible.)  What could it be?  I remember a story/joke
about an APL programmer who said that the reason he liked APL was that
with most other languages his (non-technical) manager could make
some sense of the code, and so didn't appreciate it as much, but
with APL it was totally incomprehensible and so the manager was
in awe, and of course paid more.  Maybe that's it.  Enough already.

-- 
Richard Minner  || {uunet,sun,well}!island!rtm     (916) 736-1323 ||
                || Island Graphics Corporation     Sacramento, CA ||



More information about the Comp.lang.c mailing list