Here is an example that features both indentation and alignment:
-class person
-{
+class person {
string name; // person's full name
int age; // age in years
};
of 8:
|-------|-------|-------|-------|-------|-------|------- <- tab stops
-class person
-{
+class person {
::::::::string name;::::// person's full name
::::::::int age;::::::::// age in years
};
Now somebody who prefers a tab-size of 4 looks at the code:
|---|---|---|---|---|---|---|---|---|---|---|---|---|--- <- tab stops
-class person
-{
+class person {
::::string name;::::// person's full name
::::int age;::::// age in years
};
(remember, ':' are Tabs, '.' are Spaces):
|-------|-------|-------|-------|-------|-------|------- <- tab stops
-class person
-{
+class person {
::::::::string name;..// person's full name
::::::::int age;......// age in years
};
tab-size, and it still looks good:
|---|---|---|---|---|---|---|---|---|---|---|---|---|--- <- tab stops
-class person
-{
+class person {
::::string name;..// person's full name
::::int age;......// age in years
};
One word: K&R, also known as "One True Brace Style", suitably extended for
C++. The opening brace goes at the end of the line, except for function
-bodies and classes. Really short functions can be written in one single line.
+bodies. Really short functions can be written in one single line.
if (a == b) {
// do something
// catchall
}
- class foo
- {
+ class foo {
public:
foo(int i) : x(i)
{