Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!rochester!rit!cci632!ccicpg!felix!asylvain From: asylvain@felix.UUCP (Alvin E. Sylvain) Newsgroups: comp.lang.c Subject: Re: a style question Message-ID: <151834@felix.UUCP> Date: 2 Oct 90 19:23:27 GMT References: <7341@darkstar.ucsc.edu> Sender: daemon@felix.UUCP Reply-To: asylvain@felix.UUCP (Alvin E. Sylvain) Organization: FileNet Corp., Costa Mesa, CA Lines: 40 In article <7341@darkstar.ucsc.edu> aryeh@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@cash.ucsc.edu or >"ain't bug hunts the funnest" tsource@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