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 must also allow for modification and extension, and communicate what it does to the reader. If code doesn’t do these things, then it’s ‘broke’ and needs fixing.
Code Smells
A code smell is an indication that something is wrong with the code. For example: use of statics, variables with wide scope, long methods, big classes, empty catch clauses, comments, etc. Typically, code smells are targeted during refactoring as they indicate problem areas that need attention.
As a result of refactoring:
- Code quality improves
- Complexity is reduced
- Maintenance is easier
- Code readability improves
LogicBoost’s Bryant Smith has converted programming expert Martin Fowler's refactoring example to C#.
PDF: Bryant Smith’s Refactoring in C#