As with many other things, it’s important not to allow rules with purpose. The purpose of the indentation makes the code more understandable and understandable, providing an additional visual hint of what belongs. Now, in the specific cases that you mention, along with namespace s, in many cases the extra indentation does not help in readability. case in the switch can be understood as if-else s, where you do not add extra indentation. Cases are block delimiters, similar to braces.
switch ( var ) { case 1: // if ( var == 1 ) { code; case 2: // } else if ( var == 2 ) { code; }
At the class level, access modifiers can be considered block separators at the same level as the cluster. Adding an extra level of indentation does not make the code more understandable:
class test { public: void foo(); private: int member; };
The same thing happens with namespaces, where some people avoid retreating from the entire level of the namespace. In all three cases, there is no clear advantage in adding extra indentation, and if you observe short lines of code (80/100 characters) and sufficiently large levels of indentation (8 or even 4 characters), then there may be an advantage not to indent.
Personally, I have never backed off case or access modifiers, in the case of namespace s, it depends ... a namespace that spans the entire source file will most likely not be indented, and namespaces that only take part in the source file will be indented - it is reasonable that in the first case it does not add any actual value, and in the second it does.
David Rodríguez - dribeas Nov 28 '10 at 23:51 2010-11-28 23:51
source share