Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!uflorida!ukma!tut.cis.ohio-state.edu!osu-cis!att!cbnews!apc From: apc@cbnews.ATT.COM (Alan P. Curtis) Newsgroups: comp.lang.c Subject: Re: Standard indentation? Message-ID: <2665@cbnews.ATT.COM> Date: 16 Dec 88 17:40:07 GMT References: <1988Dec8.173158.11839@utzoo.uucp> <846@starfish.Convergent.COM> Reply-To: apc@cbnews.ATT.COM (Alan P. Curtis) Organization: AT&T Bell Laboratories Lines: 98 In article <846@starfish.Convergent.COM> jerry@starfish.Convergent.COM (Gerald Hawkins) writes: +- +There are several main styles I have observed in my short experience with +C: + +The next major thing is where to put your '{' and '}'s: + + for(a = 1; a < 27; ++a) + { + ... + ... + } + +OR, + for(a = 1; a < 27; ++a) { + ... + ... + } OR (my favorite): for(a = 1; a < 27; ++a) { ... ... } +Of these two, I prefer the former. I like mine because then you can say that the "right way" to right a loop is for(....) statement; where statement can be either statement; or { statements; } And life is simple again. +Then there is the matter of how you handle do-while loops: + + do + { + ... + ... + } while (x != EOF); +OR + do /* while (x != EOF) */ + { + ... + ... + } while (x != EOF); +OR + x = 99; /* junk value so x doesn't equal EOF to start off */ + while (x != EOF) + { + ... + ... + } + +Here, the middle version is my favorite. Or in my system do { ... ... } while (x != EOF); Same reasons above. I do NOT like the repeated statement comment idea, cause it is hard to maintain. If I change while condition, *I* must rember to change comment, else tis very bad. +Here is a confusing one: +Is it ever ok to use the form: + if (a = b * 2 + 39) +INSTEAD OF: + a = b * 2 + 39 /* more normal */ + if (a) + ... +I say "no!" The code is unsupportable. EVERYONE who ever reads it will >assume it is a trivial error (and perhaps try to correct it). YES! if(a = 3*b) is FINE. Well, sortof. provided you right == this way: if(3*b == a) /* notice reversedness */ Then one cannot be confused. Of course you do have to sometimes do: if( (a=b) != 0) in the simple assignment case. apc -- Alan P. Curtis | AT&T Bell Labs | apc@cblpe.ATT.COM