Coding Standards and Naming Conventions

Indenting and Whitespace

Use an indent of 2 spaces, with no tabs. Lines should have no trailing whitespace at the end.

Operators

All binary operators (operators that come between two values), such as , -, =, !=, ==, >, etc. should have a space before and after the operator, for readability. Unary operators (operators that operate on only one value), such as +, should not have a space between the operator and the variable or number they are operating on.

Casting

Do not put a space between the (type) and the variable in a cast. In case when it’s possible to us “as” keyword it’s better to use it, instead of cast.

Curly braces

You are strongly encouraged to always use curly braces even in situations where they are technically optional. Having them increases readability and decreases the likelihood of logic errors being introduced when new lines are added.

Class Naming

Class names must be nouns or noun phrases. Use Pascal Casing. Do not use any class prefix.

Interface Naming

Name interfaces with nouns or noun phrases or adjectives describing behavior. Use Pascal Casing. Use ’I’ as prefix for the name, it is followed by a capital letter (first char of the interface name).

Enum Naming

Use Pascal Casing for enum value names and enum type names. Don’t prefix (or suffix) a enum type or enum values.

Const Field Names

Name const fields with nouns, noun phrases or abbreviations for nouns. Use Pascal Casing.

Parameter

Do use descriptive names, which should be enough to determine the variable meaning and it’s type. But prefer a name that’s based on the parameter’s meaning. Use Camel Casing.

Non const field Names

Do use descriptive names, which should be enough to determine the variable meaning and it’s type. But prefer a name that’s based on the parameter’s meaning. Use Camel Casing. Use ‘_’ as prefix(first char of the field name).

Variable Names

Counting variables are preferably called i, j, k, l, m, n when used in 'trivial' counting loops. Use Camel Casing.

Method Names

Name methods with verbs or verb phrases. Use Pascal Casing.

Property Names

Name properties using nouns or noun phrases. Use Pascal Casing.
Consider naming a property with the same name as it’s type

Event Names

Name event handlers with the EventHandler suffix. Use two parameters named sender and e. Use Pascal Casing. Name event argument classes with the EventArgs suffix. Name event names that have a concept of pre and post using the present and past tense. Consider naming events using a verb.

Download code samples CodeSamples.cs

Last edited Nov 15, 2010 at 9:07 AM by dnovikov, version 2

Comments

No comments yet.