Most of us will be aware that there are two very popular styles of C++ coding: K&R and ANSI.
On the whole, they aren't really all that much different from each other, and have their merits.
The most visible and obvious difference is, I think, the treatment of whitespace and the use of braces in compound statements.
Some examples (surrounding code omitted for brevity):
K&R style:
ANSI and ISO C++ style:Code:while (j != 1) { i++; if (i == 100) { j = 1; } }
With C, the choice is clear. ANSI/ISO seem to follow the K&R style in its C standard documentation.Code:while (j != 1) { i++; if (i == 100) { j = 1; } }
With C++, ANSI/ISO differ from K&R. ANSI/ISO have a coding style which advocates placing the opening "{" brace on a line of its own.
Which style is your preference?
For me, I prefer K&R due to my C and Java background (note: Java uses a style similar to K&R but not identical). ANSI/ISO's style appears to waste too much space. I appreciate the clarity of having the opening brace on its own line, but it is usually unnecessary.
Bookmarks