a style question

don provan donp at na.excelan.com
Wed Oct 3 05:22:04 AEST 1990


In article <1990Oct1.174625.22061 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
>In article <1990Sep30.220839.20183 at nntp-server.caltech.edu> manning at nntp-server.caltech.edu (Evan Marshall Manning) 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 in
>this context.  If the name is not going to be meaningful -- and in the
>context of a short loop, it's not clear that making it meaningful is
>either possible or particularly important -- then at least keep it short.

The reason both are meaningless is because there *is* no context: this
is just a code fragment.  In practice, i've never encountered a loop
that wasn't counting *something*, so why not name it?  I agree that
"ix" is nearly as bad as "i", and "loopindex" is worse than either.
The fact that this variable is an index is its *least* interesting
attribute.  An index into *what*?  *That's* the important point.

My attitude is just the opposite of yours: to me, the shorter the loop
is, the less excuse there is to choose a name because of it's length.
If you're only going to be typing the name three or four times, what's
the advantage keeping it a single character?  Readability?

						don provan
						donp at novell.com



More information about the Comp.lang.c mailing list