Allman Style
The Allman style is named after Eric Allman. It has been incorrectly referred to as "ANSI style" supposedly for its use in the documents describing the ANSI C standard (later adopted as the ISO C international standard), though in fact those documents use K&R style. It is also sometimes known as "BSD style" since Allman wrote many of the utilities for BSD Unix (although this should not be confused with the different "BSD KNF style"; see below).
This style puts the brace associated with a control statement on the next line, indented to the same level as the control statement. Statements within the braces are indented to the next level.
while (x == y) { something; somethingelse; } finalthing;This style is similar to the standard indentation used by the Pascal programming language and Transact-SQL, where the braces are equivalent to the begin
and end
keywords.
Advantages of this style are that the indented code is clearly set apart from the containing statement by lines that are almost completely whitespace, improving readability, and the closing brace lines up in the same column as the opening brace, making it easy to find matching braces. Additionally, the blocking style delineates the actual block of code from the associated control statement itself. Commenting-out the control statement, removing the control statement entirely, refactoring, or removing of the block of code is less likely to introduce syntax errors because of dangling or missing brackets.
For example, the following is still syntactically correct:
//while (x == y) { something; somethingelse; }As is this:
//for (int i=0; i < x; i++) //while (x == y) if (x == y) { something; somethingelse; }Even like this, with conditional compilation:
char c; #ifdef HAS_GETCH while ((c = getch) != EOF) #else while ((c = getchar) != EOF) #endif { do_something(c); }A disadvantage of this style is that each of the enclosing braces occupies an entire line by itself without adding any actual code. This once was an important consideration when programs were usually edited on terminals that displayed only 24 lines, but is less significant with the larger resolutions of modern displays. Since the motivation of this style is to promote code readability by visually separating blocks from their control statements, screen real estate is only a secondary concern.
This style is used by default in Microsoft Visual Studio 2005 and later versions. Microsoft has since then adopted the style throughout all of its documentation (MSDN) and internal programming methodologies for its C-based languages, namely C++ and C#.
Read more about this topic: Indent Style
Famous quotes containing the word style:
“No change in musical style will survive unless it is accompanied by a change in clothing style. Rock is to dress up to.”
—Frank Zappa (19401994)