a style question

Michael J Zehr tada at athena.mit.edu
Wed Oct 24 02:01:16 AEST 1990


In article <443 at mole-end.UUCP> mat at mole-end.UUCP (Mark A Terribile) writes:
>> >>Don't ever use single-character variable names.  I use 'ix' for
>> >>loop index variables for which I can come up with no better name...
>
>> >In what way is "ix" superior to "i"?  Both are meaningless names ...
>> >If the name is not going to be meaningful ... then at least keep it short.

Okay, I'll bite on this one.  First, a disclaimer that I usually use "i"
as a loop variable anyway.

"ix" is superior because "i" can sometimes be confused with "1",
depending on your printer.  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?

using a 2-character loop variable makes this much less likely to happen.

-michael j zehr



More information about the Comp.lang.c mailing list