C# Coding Style – Is Awkward Spacing a Style?

ccoding-style

In reading another programmers code, he uses a format I have never seen. E.G.

    namespace MyNs.HereWeAre
         {//tab here for some reason
         public class SomeClass
               {//here's another tab
               public string Method()
                    {//yet another tab
                    string _variable = "";//no tab implementation
                    return _variable;
                    }
               }//eof - class  (Yes these eof comments are on every file)
        }//eof - namespace
// eof - file

I'll admit…this code makes me angry. It is difficult to achieve this style. One needs to fight the default formatting provided by the IDE, visual studio.

I could swallow this pill a little easier if I knew that there was a good reason for this style. Does this style stem from some other programming language/IDE?

Best Answer

Yes: http://en.wikipedia.org/wiki/Indent_style#Whitesmiths_style

The Whitesmiths style, also called Wishart style to a lesser extent, is less common today... It was originally used in the documentation for the first commercial C compiler, the Whitesmiths Compiler. It was also popular in the early days of Windows, since it was used in three influential Windows programming books, Programmer's Guide to Windows by Durant, Carlson & Yao, Programming Windows by Petzold, and Windows 3.0 Power Programming Techniques by Norton & Yao...

This style 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...

The advantages of this style are similar to those of the Allman style in that blocks are clearly set apart from control statements. However with Whitesmiths style, the block is still visually connected to its control statement instead of looking like an unrelated block of code surrounded by whitespace. Another advantage is that the alignment of the braces with the block emphasizes the fact that the entire block is conceptually (as well as programmatically) a single compound statement. Furthermore, indenting the braces emphasizes that they are subordinate to the control statement.

A suggested disadvantage of this style is that the ending brace no longer lines up with the statement it conceptually belongs to. However, the closing brace belongs to the opening brace and not to the control statement...

It's one I've never seen practiced though, thank IPU.

Eclipse has a built in Whitesmith code style for c++...you might be screwed with Java since everyone is supposed to use the same style in that language.

Related Topic