-
Improve Conditional
-
Why?
- Reduce the complexity
- Improve readability
- Improove maintainability
- Improve reusability
-
When?
- When there is more than one condition (and / or)
- When there is too much code inside in the body
- When the if is based on string or type
-
How?
-
Refactor if statement
- Replace complex expression with method call
- Flatten nested if
-
Avoid if statement
- Replace if statement with derived type
- Use strategy pattern
- Delegate implementation
-
Invert if statement
- Don't use negative
- Write if statement so the least amount of code is in it
-
Improve Documentation
-
Why?
- Improve readability
- Improove maintainability
- Avoid obsolete comments
-
When?
- Every time there is a comment that describe something else than intention
-
How?
-
Replace comment with code naming
- Extract method
- Use meaningful names
-
Naming Conventions
- Properties
- Enums
- Events
- Protected
- Actions
-
Improve Method call
-
Why?
- Improve performance
- Improve readability
- Improve reusability
-
When?
- When there is more than 2 parameters
- When there are many out parameters
- When you need default valies
-
How?
-
Reduce number of parameters
- Encapsulate parameters in type
- Create overload with less parameters
- Use default value
- Return type value
- Use out paramters
- Overload method in proper order
-
Manage Scope
-
Why?
- Avoid side effect
- Improve reusability
- Improve maintainability
-
When?
- A field is used in few methods
- Public members expose class behaviour
-
How?
-
Reduce visibility
- Use protected
- Use private
- Use Internal
-
Reduce scope
- Move fields to method
- Split class
- Move local variable close to its use
-
Reduce lifetime
- Initialize late
- Reduce references
- Free early
-
Remove Dead code
-
Why?
- Because you must
- Improve maintainability
- Improve performance
- Improve readbility
-
When?
- You know the code is dead
- You think the code is dead
- You want that code to be dead
-
How?
- Identify dead code
- Remove code