Skip to content
alastairs edited this page Jan 28, 2012 · 2 revisions

Coding Standards

Code requirements

Clean Code

Committed code should adhere to the SOLID principles. GiveCRM uses Ninject to handle dependency injection, and has been configured to auto-wire concrete classes to interfaces using the convention IFoo resolves to a class called Foo.

Variables, methods, classes and all other identifiers should have meaningful and descriptive names.

Unit Tests

All code introduced should be covered by unit tests at a minimum, with integration tests and acceptance tests where appropriate. Unit tests should be:

  • Explicitly named
  • Short (max. ~12 lines)
  • Very fast to run (a few milliseconds per test method)
  • Follow the Arrange-Act-Assert pattern

Refactoring

Technical debt should be paid down when it starts to hurt. Have you found a bit of the codebase that doesn't adhere to these rules? Tidy it up and submit a pull request!

StyleCop settings

To help code maintainability and readability StyleCop will be used to enforce a few rules. Currently all projects are using the one setting file found in the src directory. A ReSharper settings file provides development-time assistance in conforming to the GiveCRM coding standards.

Layout rules

Always include curly braces (this means you can't miss out curly braces on single line if blocks)

Maintainability rules

Unnecessary code must be removed.

Access Modifiers

  1. Access modifiers must be declared
  2. Fields must be private

Debug text

  1. Code analysis suppression must have justification
  2. Debug.Asserts must provide a text message
  3. Debug.Fail must provide a text message

Naming rules

  1. Interface names must begin with an I
  2. Const field names must begin with an upper case letter
  3. Field names must not use Hungarian notation
  4. Field names must begin with a lower case letter
  5. Variable names must not be prefixed (no putting _ or m_ infront of them)
  6. Field names must not begin with an underscore

​Ordering rules

consts must appear before fields.

Readability rules

  1. Comments must contain text
  2. Don't use regions
  3. Code must not contain empty statements
  4. Use string.Empty not ""
Clone this wiki locally