
why no braces for single statement blocks?
Quote:
> for (i=0;i<10;i++) {
> while (j<k) {
> if (j<m) {
> printf("bla");
> }
> }
> }
My vote would be for...
if (j < k && j < m) for (i = 0; i < 10; i++) printf("bla");
thus avoiding an infinite loop when j is less than k. It's also
interesting that the style above, which throws away vertical space
on extra braces and uses very big indentation, skimps on what some
people might consider the important bits, within the ()s.
Quote:
> I prefer K&R
I just opened my copy of K&R2 to a page somewhere in the middle
that has some code on it, and noticed...
o Indents are 4 spaces (remember hard tabs aren't totally
portable).
o No extra braces are used, despite single-statement while/if/if
and for/if constructs.
o Expressions within ()s are almost always spaced out nicely.
Code layout is obviously a thing that varies from programmer to
programmer, and I think it tends to evolve too as one gets
increasingly comfortable with the language. One gets to trust
things like operator precedence (leading to a = b + c * d instead
of a = b + (c * d)), or, in this case, statement blocking.
--
*** Count Templar, ELITE, Cobra Mk III (FM-287) ***