Refactor!
You’re about to add a feature, but it looks difficult to do. You need to fix a bug, but you don’t understand the code. You’re doing a code review and you have a suggestion. What do you do? Refactor!
Of the books on my bookshelf, Refactoring: Improving the Design of Existing Code by Martin Fowler is the initial reference on this topic. Identify the code smell (in chapter 3, written with Kent Beck) and select a suggested refactoring, a catalog of which is the heart of the book (in chapters 5 through 12). Industrial Logic has posted a “Smells to Refactorings Quick Reference Guide” that summarizes these smells as well as the refactorings in Refactoring to Patterns.
Yes, 1999 was a decade ago, so the technology has changed. The JUnit–and NUnit–test frameworks (chapter 2) now use annotation. Refactoring tools (chapter 14) like ReSharper or those in Eclipse are better. The principles, however, still apply. Refactor!
