Standard indentation?
Alan P. Curtis
apc at cbnews.ATT.COM
Sat Dec 17 03:40:07 AEST 1988
In article <846 at starfish.Convergent.COM> jerry at 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 at cblpe.ATT.COM
More information about the Comp.lang.c
mailing list