Proposal for a scientific look at C style choices

T. William Wells bill at twwells.uucp
Sat Dec 24 10:16:42 AEST 1988


In article <eWl9H#2cdgbS=eric at snark.UUCP> eric at snark.UUCP (Eric S. Raymond) writes:
: Let's start by mapping a really major node. Maybe the most basic question
: in C layout is:
:
: Question A: Which do you value more; conservation of vertical space, or a
: global rule that start braces go at the same visual indent level as their end
: braces?
:
: If your answer is "value conservation more", then you are likely to use
: Kernighan & Ritchie style:
:
: if (cond) {
:      /* stuff */
: }

I believe that there is an alternate rationale for the above style:
that braces exist only to make the compiler happy and should therefore
be as unobtrusive as possible. This is why I use the above; I recall
dmr saying that that is his reason as well.

However I do value conservation of vertical space. Which is why, for
the purposes of deciding whether a blank line should be inserted, I
consider a line containing a brace to be equivalent to a blank line.

: Question B: in control structures, do you consider the braces to be more
: firmly glued to a) the "guard" part, or b) the enclosed statement(s).
:
: If your answer to "B" is a), you're likely to plump for the Pascal-oid layout.
: If it's b), you probably like some Whitesmiths variant. I *think*. I'm inviting
: comment on all this.

I consider the braces as a separate element: sometimes necessary for
the compiler (but I always use the braces), but contributing little or
nothing to the understandability of the program.  The indentation of
the program is what tells you the control relationships; the braces
are redundant information, at best they can augment what the
indentation is alreaddy telling you.

---
Bill
{uunet|novavax}!proxftl!twwells!bill



More information about the Comp.lang.c mailing list