2007/10/19

C# Coding Style

I believe most of the programmers know how important coding style is, and what benefits that it will bring to us. However, I haven't found any official .Net coding style document, and that's why there are many versions of coding style sheets/documents around us. Some companies even have their own coding style.

Most people will recommend this one: http://www.icsharpcode.net/TechNotes/

But if you really follow the coding style when you are coding in Visual Studio 2005 environment, you will find that VS 2005 IDE will automatically format your code which is different from the coding style document that I mentioned above. For example, your original code looks like this
try {
 ...
} catch (Exception e) {
 ...
}

it will be changed to
try 
{
 ...
}
catch (Exception e)
{
 ...
}

This is just an example, and I believe you can find many others. (However, you can change this settings in VS2005 by selecting Tools -> Options -> Text Editor -> C# -> Formatting -> New Lines)

I think MS already has a standard style (built in Visual Studio 2005) for how codes should look like, and he only left naming convention for us to play.

PS1: You can also press Ctrl-K + D to format your code manually.
PS2: I found that Microsoft actually has its own Naming Guidelines. Someone already organized well for us, see here.
PS3: There is another good C# Coding Standards wrote by Lance Hunt at here.

No comments:

Post a Comment