-
Notifications
You must be signed in to change notification settings - Fork 16
Coding Standards
jpetrie edited this page Jul 2, 2011
·
1 revision
In general, we use the code formatting options provided by Visual Studio 2010's "Visual C#" default configuration, with one exception (format with tabs, not spaces). Additionally, we use the following rules:
- Each statement should get its own line.
- Braces should be omitted when possible.
- However, braces should only be omitted for complex control constructs (
if
/else
,try
/catch
) if they can be omitted for all blocks in the construct. - Access modifiers should be omitted when possible.
- Use the .NET guidelines unless superseded by a directive of this style guidelines document.
- Use
var
when possible. - Do not created nested types.
- Do not create more than one type per file.
- Identifiers should be named in such a way as to clearly illustrate their purpose or meaning. Abbreviations should be avoided.
- Pascal case should be used for types, methods and properties. Camel case should be used for variables and fields.
- All letters of an acronym should be capitalized, except with the acronym is the first word of a camel case identifier, in which case all letters should be lowercase.
- Boolean properties should begin with a word that suggests their boolean nature, such as "is."
- Do not decorate field names with prefixes (for example, with
m
). - Do not decorate type names with prefixes (for example, with
I
). - In declarations, the access modifier (if applicable) should precede the static/virtual/et cetera designator.
Comment intelligently; don't comment code that is otherwise readable and self-documenting. Instead, prefer to comment only where value would be added, such as by explaining why a particular implementation was made in favor of another that might be more obvious or standard.
- C-style comments should be avoided.
- There should be a single blank line between the last line of a file header copyright and the first line of code.
- Comments should not be placed on the same line as code statements.
- Insert a space between the comment delimiter and the first character of the comment.
- XML documentation comments should be added to every non-private item.
- Prefer to avoid committing large blocks of commented-out code. That's what version control is for.