Indent style
In computer programming, an indent style is a convention governing the indentation of blocks of code to convey the program's structure. This article largely addresses the C programming language and its descendants, but can be (and frequently is) applied to most other programming languages (especially those in the curly bracket family). Indent style is just one aspect of programming style.
Whitesmiths style
The Whitesmiths style is relatively common. It puts the brace associated with a control statement on the next line, indented. Statements within the braces are indented to the same level as the braces.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
while (x == y)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
something();
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
somethingelse();
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
}
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
finalthing();
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
The perceived advantages of this style are similar to those of the BSD style. Advocates of this style believe that the braces combine a series of declarations and statements into a single statement. Therefore, they should be indented as subordinate to the control statement instead of lined up with it.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Proponents of the BSD style argue that the Whitesmiths style has the disadvantage that the braces do not stand out as well. This is largely a matter of opinion; it could be argued that the brace stands out equally well being the last thing more indented as the first thing indented to the previous level.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Another disadvantage of this style is that while it works well with statements, it does not work as well with some other language structures. For example, class visibility identifiers in C++ can be difficult to spot. There are ways to mitigate this somewhat, such as using a blank line before scope identifiers (and nowhere else), but this is not a part of indent style.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
class Foo class Foo
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
private: private:
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
void func1(); void func1();
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
void func2(); void func2();
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
public:
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
void func3(); public:
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
void func4(); void func3();
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
}; void func4();
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
};
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ Table of Content ~
| ► | Introduction |
| ► | K&R style |
| ► | BSD/Allman style |
| ► | Whitesmiths style |
| ► | GNU style |
| ► | Pico style |
| ► | See also |
~ What's Hot ~
~ Community ~
| ► | History Forum Come and discuss about History, Civilizations, Historical Events and Figures |
| ► | History Web-Ring A community of sites, blogs and forums dedicated to History. Do not hesitate to submit your site. |
and are licensed under the GNU Free Documentation License.
Lexicon - Privacy Policy - Spiritus-Temporis.com ©2005.