C bites / programming style [if
jrife at fthood
jrife at fthood
Wed Aug 28 22:48:00 AEST 1985
> If the body is more complicated than an assignment or function
>call, I put it in braces, even though they really aren't needed, thus:
>
> while ((foo = getfoo()) != EOF) |
> { | for (x=0; x <= 10; x++)
> if (foo >= bar) | {
> sum += foo; | for (y=0; y <= 10; y++)
> else | sumxy += x * y;
> toosmall++; | }
> } |
>
I like this programming style myself, Roy. But, one suggestion...if you move
the braces over, you end up with the braces in line with the level of
complication, and then *only* the opening and closing braces of a function are
in the first column, thus:
while ((foo = getfoo()) != EOF)
{
if (foo >= bar)
sum += foo;
else
toosmall++;
}
It also makes constructs such as:
while ((foo = getfoo()) != EOF)
{
if (foo >= bar)
{
sum += foo;
bar = stuff * 3;
}
else
{
toosmall++;
if (garbage != foo)
garbage--;
}
}
easy to understand. And, now, autoindent on vi works very nicely.
--
*********************************
* *
* Jeff Rife *
* ihnp4!uiucuxc!fthood!jrife *
* *
* "Gene Simmons never had a *
* personal computer when he *
* was a kid." *
* --Berke Breathed *
* *
*********************************
More information about the Comp.lang.c
mailing list