Tabs And Indentation
From K-3D
The traditional K-3D style has been to indent twice on if-statements and loops, once for the braces (on their own lines, of course), and once for the body of the block.
Surprisingly (not least of all to me), I had a recent contract where I actually liked a different style guideline, which is to align the braces (still on their own lines, goddammit!) with the if-statement / loop. Three things about it that I appreciated:
- The indentation is the same whether you follow a conditional with a single statement or a block, e.g if you move from:
if(foo) bar();
to:
if(foo) { bar(); baz(); }
... you don't have to change the indentation. Even if you aren't changing back-or-forth, identical nesting levels have identical indentation.
- Consistent indentation WRT methods and classes, e.g, the old style is a mixture of single- and double-tabs that align in some cases and not others:
class foo { void bar() { if(baz) { buz(); } } };
... while the new style is much more consistent:
class foo { void bar() { if(baz) { buz(); } } };
- Uses-up less screen real-estate, which wasn't a revelation to me of course, but I seem to appreciate it more than I used-to.