Linux Coding Standard
I have been looking at a few coding standards recently and for the most part, I am happy with the Linux kernel coding style (http://www.kernel.org/doc/Documentation/CodingStyle). It has a very nice description of how to code everything in a terse but clear way which is something a lot of other guides lack. There are two items with it though that I definitely do not agree with: the indentation for switch statements and the use of braces in if/else statements.
For switch statements, the coding style recommends having the case statements at the same indentation level as the switch statement (see below)
switch (suffix) { case a: break; default: break; }
In my opinion, this is hard to read and the case statements should all be indented by another level (see below)
switch (suffix) { case a: break; default: break; }
The style also specifies that curly braces should not be used with conditional statements unless one branch consists of multiple statements. I completely agree with this concept for a single if statement, however, I think it looks a lot cleaner to use braces if there are multiple branches in the if statement. This does not add a significant amount of white space (only a single line thanks to the inline braces), gives a cleaner separation, and prevents people from stupidly adding an extra statement they think is in a branch but really is not. The change I am proposing is below.
if (cond) action(); else other_action();
would become
if (cond) { action(); } else { other_action(); }
With these two changes (and adaptations for things like classes and other non-C language features), I will be using the Linux Kernel Coding Style as my personal coding style. There are times when I do things wrong (for example, I often do not put spaces around “*” and “/” just because my Engineering 101 professor instructed us not to) but overall this is a nice sound style guide and one I will be happy trying to follow.