Declare variables in the narrowest possible scope.Confine Variables to a Single Purpose
Permit variables to only perform storage of a single piece of data.Avoid Hard-Coded Numbers
Instead, make use of the languages const keyword for all values not zero or one.
Try to keep the number of method arguments low. More than four to six parameters may warrant creation of an object for passing into the routine.Avoid Reference Parameters
Methods should typically accept objects or parameters passed by value.Confine Methods to a Single Purpose
For understandability, methods should do only one thing. Keep methods short.
By using methods or properties to access variables, an additional layer of safety can be provided and flexibility exists for changing variable access behavior.Code to Interfaces
For additional flexibility and maintainability, create interface classes at the top of the class hierarchy that generically define object behavior, then implement that behavior through subclasses.Initialize Late, Dispose Early
To improve performance, never initialize objects before they are needed and release them as soon as possible.
Perform both client-side and server-side data validation to improve usability, security, and performance.Exceptions
For performance and understandability, handle specific exceptions. Don't catch exceptions which are not handled.Don't Use Exceptions for Control Flow
Exception handling may not be optimized for code execution and placing code there is likely to reduce understandability.
By narrowing the scope of changes and testing frequently, it is much easier to observe, locate, and repair faults.Comment Your Code
Well written code should be self-documenting, so avoid stating obvious functionality. Instead, list assumptions and describe subtleties.
Instead of commenting old code, rely on version control to keep code that may need to be re-implemented.
Simpler code presents less opportunity for bug creation and improves readability.
For clarity, try to minimize evaluation of negative conditionals.
Use descriptive variable and method names. Single character iterators (e.g., i, j, and k) that quickly fall out of scope are permissible but meaningful variables deserve meaningful names. As a rule of thumb, the wider the variable's scope, the more descriptive its name should be.Be Consistent
Use strategies and conventions consistently throughout the code.