Refactoring code involves implementing small steps to improve the design of the existing code without changing the functionality.
What happened to “If it ain’t broke, don’t fix it”?
Code has to do more than just work … it also needs to
- Allow for modification and extension
- Communicate what it does to the reader.
If code doesn’t do these things, then it is "broke" and needs fixing.
Code Smells
An indication that something is wrong with the code (Examples: use of statics, variables with wide scope,
long methods, big classes, empty catch clauses, comments, and more). Code smells should be targeted when refactoring
as they indicate problem areas that need attention.
- Benefits for Refactoring Code:
- Improved quality
- Reduce complexity
- Ease of maintenance
- Improves readability of code
Bryant Smith has converted Martin Fowler's refactoring example to C#.
Refactoring in C#