a style question

Alvin E. Sylvain asylvain at felix.UUCP
Wed Oct 3 05:23:27 AEST 1990


In article <7341 at darkstar.ucsc.edu> aryeh at cash.uucp (the over worked C something or another) 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++) ...
>
>-- 
>Aryeh Friedman 				aryeh at cash.ucsc.edu or
>"ain't bug hunts the funnest"		tsource at watnxt2.ucr.edu

YES, is bad style.  First off, *never* compare *exactly* against the
end-value, *always* use <, or <=, as the case may be.  This is due
to the fact that occaisionally x may change within the loop (either
deliberately, or accidentally).  So, it advances to 97, 99, 101, 103,
(oops, we passed 100!), ad infinitum.

Secondly,putinmorespacesforreadability:

       for (x = 0; x < 100; x++) ...

although I don't beef at people who prefer a bit less space:

       for (x=0; x<100; x++) ...

and to REALLY get your style down to something maintainable, get rid of
those so-called "magic numbers", e.g.:

       #define MAX_DOODLES 100
          ...
       for (x = 0; x < MAX_DOODLES; x++) ...

This can open an entire can of worms.  You might as well get out your
pen and paper and write down all your style questions, put them in a
single posting, and request E-mail responses.  Give it a week or so,
then post a summary of your results.  We'll be interested in seeing
the opinions on this very, very personal subject!
--
-=--=--=--"BANDWIDTH??  WE DON'T NEED NO STINKING BANDWIDTH!!"--=--=--=-
"If you come in at 10am and leave at 7pm one day, then come in at 6am
and leave at 3pm the next day, people will deduce that you are coming in
at 10am and leaving at 3pm every day." --- me



More information about the Comp.lang.c mailing list