Importance of style guidelines
Defining and following the coding style guidelines is not just nice to have, but it is very very important. It doesn’t matter whatever guidelines you choose, but it is crucial to choose something. Why? Because it leads to cleaner, readable and maintainable source code. And maintaining code is a part of development, not just something in the future.
My preferred style guidelines
Here are guidelines which I always use (when it is possible). Most of these guidelines are blessed by creators of C# language, but I did some meaningful changes.
Private members- _lowerCamelCase (with prefix _) and use readonly where possible.
method parameters- lowerCamelCase
Non private methods,
static readonly fields- ALL_UPPER
Generic types- TUpperCamelCase
- Avoid this. unless absolutely necessary.
- Always specify the visibility (private string _foo)
- Use Allman style braces, where each brace begins on a new line. A single line statement block can go without braces but the block must be properly indented on its own line and it must not be nested in other statement blocks that use braces
- Include unit tests when adding new features. When fixing bugs, start with adding a test that highlights how the current behavior is broken.
Order of items in classes
- Constant Fields
- Finalizers (Destructors)
- Public methods
- Private methods
- Implementation of interfaces (each in own region)