Chapter 3. Code Smells and Refactoring
In the previous chapter, we went through the TDD cycle in a little more detail. In this chapter, we will look at the related concept of code smells and refactoring.
One of the biggest advantages of following a test-driven development process is that the tests that we write are always around to make sure that we don't break anything. This gives us a safety net to tinker with the code and make sure that it is easy to read, easy to maintain, and well written. Without tests, we always have a nagging doubt about whether we are about to break something, and more often than not we decide to leave things alone. This leads to the code decaying over time, until it is such a mess that no one wants to touch it anymore. The result is that it takes longer to implement new features, not only because the design is a mess, but also because we have to follow it with extensive testing to make sure none of the existing functionality has broken.
For this reason...