a style question

Evan Marshall Manning manning at nntp-server.caltech.edu
Wed Oct 3 02:38:53 AEST 1990


I wrote:
>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...

henry at zoo.toronto.edu (Henry Spencer) writes:
>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.

If Henry asks it must not be as self evident as I thought.  Hasn't this
ever happened to you:  You're thinking that you could apply what you
just learned on the net and speed up this time-critical bit of code by
changing the original cout-up loop to a count-down loop.  "But wait," you
say, "What if some later code depends on the value of 'i' after exiting
the loop?  I'll just search for the letter 'i' through 100 lines of
source."  You find that a lower case 'i' appears an average of about
four times per comment line.  'ix' appears in the comments only when
the comments are about variable 'ix'.  Or, similarly, you 'grep' 'i'.

What's actually happened to me more often is that lint tells me that
a variable is not used in a procedure but I want to check that it is
not used in any #ifdef'd code before removing the declaration.

Doesn't this happen to anybody else?  (I know Henry gets it all right
the first time, but even he must inherit code, and inherited code
always has declarations like "int    i,j,k,l,ii,jj,kk,ll,m;" and no
comments :-)

***************************************************************************
Your eyes are weary from staring at the CRT for so | Evan M. Manning
long.  You feel sleepy.  Notice how restful it is  |      is
to watch the cursor blink.  Close your eyes.  The  |manning at gap.cco.caltech.edu
opinions stated above are yours.  You cannot       | manning at mars.jpl.nasa.gov
imagine why you ever felt otherwise.               | gleeper at tybalt.caltech.edu



More information about the Comp.lang.c mailing list