My Personal Coding Standard
So I wanted to share with the world my personal coding standard. This is the coding standard I use everyday when I develop software.
Naming
- Never abbreviate, never.
- Prefix private fields with the underscore character (_). This will be the ONLY time you will use the underscore character when naming.
- Never use the underscore character for namespace, class, method, enum, enum value, event, read-only, const, interface and property names.
- Use Pascal casing for namespace, class, method, enum, enum value, event, read-only, const, interface and property names.
- Use Pascal casing for abbreviation like HTML should be Html. Ex. XML should be Xml.
- The only exception is two character abbreviations like “IO” and they should always be capitalized.
- Use camel casing for local variables and method arguments. Ex. isRunning, phoneNumber
- Prefix component / control variables with the class name. Ex. LabelName, TextBoxAddress
- Name interfaces with the “I” prefix. Ex. IConfigurable, IExtendable
- Suffix exception classes with “Exception”. Ex. InputInvalidException, TypeNotFoundException
- Use descriptive naming.
- Avoid one character variable names, such as i or t. Use index or temp instead.
- Simple “for” loops are the only exception to one letter variable names.
- Never use Hungarian notation for public or protected members. Ex. strName, intNumUsers
- Do not abbreviate works such as using num instead of number. See General 1.
- Avoid fully qualified type names. Use the “using” statement instead.
Style
- Maintain strict indentation. Always use “TAB” for indentation and never use spaces.
- All comments should pass spell checking. Misspelled comments indicate sloppy development.
- All methods should be separated by only one blank line.
- Always place an open curly brace “{“ on a new line.
- Always use curly brace scope for “if”, “for”, etc… statements, even it contains a single statement.
- Avoid multiple classes in one file. Always put clases, structures in their own file.
More to come…