The Elements of C# Style -General Principles
1. Adhere to the Style of the Original
Do not introduce a new coding style in a modification ,and do not attempt to rewrite the old software just to make it match the new style.
2. Adhere to the principle of Least Astonishment
The Principle of Least Astonishment suggests you should avoid doing things that would surprise other software developers.
To minimize the changces that anyone would encounter something surprising in your software,you should emphasize the following characteristics in the design,implementation,packaging,and documentation of your software:
Simplicity Meet the expectations of your users with simple classes and simple methods
Charity Ensure that each class,interface,method,variable,and object has a clear purpose,Explain where ,when ,why ,and how to use each
Completeness Provide the minimum functionality that any reasonable user would expect to find and use.Create complete document-action;document all features and functionality.
Consistency Similar entities should look and behave the same;dissimilar entities should look and behave differently,Create and apply consistent
standards whenever possible.
Robustness Provide predictable,documented behavior in response to errors and exceptions.Do not hide errors and do not force clients to detect errors.
3 Do It Right the First Time
Apply these rulse to any code your write,not just code destinde for production.More often than not ,some piece of prototye or experimental code will make its way into a finished product,so you should anticipate this eventuality.
4.Document Any Deviations
Before you decide to ignore a rule,you should first make sure you understand why the rule exists and what the consequences are if it is not applied .If you decide you must violate a rule,then document why you have done so.
This si the prime directice.
5.Cosinder Using a Code-Checking Tool to Enforce Coding Standards
For example,FxCop is a popular .NET code analysis tool .