Thursday, January 5, 2012

C# Coding Guidelines and Best Programming Practices


In this post I am trying to explain the best practice coding guidelines.A style guide is a set of mandatory requirements for layout and formatting. Uniform style makes it easier for other developers to grasp the essence of your programs quickly. A style guide makes you more productive because it reduces gratuitous choice. If you don't have to make choices about trivial matters, you can spend your energy on the solution of real problems.

Naming Conventions:
  • Pascal casing: The first character is upper case, and the first letter of each word is also upper case. All other characters are lower case; for example, FirstName.
  •  Camel casing: The first character is not upper case, but the first letter of each word is upper case. All other characters are lower case; for example, firstName.
  •  All Upper:All the characters are in capitals with an underscore between the two words. Example: FIRST_NAME
Source files should be kept as short as possible. Put every class in a separate file, and name that file like the class followed by the .cs extension. Map namespaces one-to-one to the directory layout. For example, if Thermota.Core is the root namespace, it should be mapped to the Thermota.Core directory, while the nested namespace
Thermota.Core.Tests should be mapped to the Thermota.Core / Thermota.Core.Tests path.
Organize the material in each source file as follows:
1.    Appropriate using statements  with using Directive region
2.    namespace statement, if appropriate
3.    A class, struct, or enum
#region using Directives
Using System;