a style question

Evan Marshall Manning manning at nntp-server.caltech.edu
Mon Oct 1 08:08:39 AEST 1990


steve at groucho.ucar.edu (Steve Emmerson) writes:

>>Since I going to be doing my first team effort I want to know if this is bad 
>>style:
>>	for(x=0;x!=100;x++) ...

>It's OK, though some improvements could be made.  Old-timers would
>ususally write  "x < 100" rather than "x != 100" as it expresses the
>sense of direction (incrementation) slightly better, and they're more
>used to seeing it that way.

>A slightly more important improvement would be to use a symbolic
>variable or constant for the, otherwise, non-obvious "100" value.
>Something like

>	# define NUM_ELEMENTS	100

>	for (x = 0; x < NUM_ELEMENTS; x++) ...

>Note also the use of additional whitespace.

Well, if the issue really is style...

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,
but this happens rarely.  If you're looping ove 'x' then 'x' means
something more to you than just 'x' when you're writing the code.
But it may not be immediately obvious later.

There's bound to be a more useful name for NUM_ELEMENTS too.

***************************************************************************
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