Braces
George V. Reilly
gvr at cs.brown.edu
Thu Feb 7 17:04:38 AEST 1991
In article <2324 at inews.intel.com> bhoughto at pima.intel.com (Blair P. Houghton)
writes:
% ... I'd like to know where it came from, not the reasons
% or rationalizations for its use: those I'll get from the
% source.
The jargon file, version 2.5.1, has this to say on the matter of
indent styles:
<indent style> [C programmers] n. The rules one uses to lay out code
in a readable fashion; a subject of <holy wars>. There are four
major C indent styles, as described below; all have the aim of
making it easier for the reader to visually track the scope of
control constructs. The significant variable is the placement of
{ and } with respect to the statement(s) they enclose and the
guard (if, while, or do) on the block, if any.
"K&R style" --- Named after Kernighan & Ritchie, because the
examples in <K&R> are formatted this way. Also called "kernel
style" because the UNIX kernel is written in it. The basic indent
shown here is 8 spaces (or 1 tab) per level; 4 is occasionally seen
but much less common.
if (cond) {
<body>
}
"Allman style" --- Named for Eric Allman, a Berkeley hacker who
wrote a lot of the BSD utilities in it (it is sometimes called
"BSD style"). Resembles normal indent style in Pascal and
Algol. Basic indent per level shown here is 8 spaces, but 4 is
just as common (esp. in C++ code).
if (cond)
{
<body>
}
"Whitesmiths style" --- popularized by the examples that came
with Whitesmiths C, an early commercial C compiler. Basic indent
per level shown here is 8 spaces, but 4 is occasionally seen.
if (cond)
{
<body>
}
"GNU style" --- Used throughout GNU EMACS and the Free Software
Foundation code, and just about nowhere else. Indents are always 4
spaces per level, with { and } "centered" between levels.
if (cond)
{
<body>
}
What style one uses is very much a matter of personal choice, but
one should be consistent within any one software package.
Statistically, surveys have shown the Allman and Whitesmiths styles
to be the most common, with about equal `mind share'. K&R used to
be nearly universal, but is now much less common (the opening brace
tends to get lost against the right paren of the guard part in an
if or while, which is a Bad Thing).
________________
George V. Reilly `Brace yerself, Bridget' gvr at cs.brown.edu +1(401)863-7684
uunet!brunix!gvr gvr at browncs.bitnet Box 1910, Brown U, Prov, RI 02912
More information about the Comp.lang.c
mailing list