Chapter 4. Refactoring

This chapter covers

  • Methods for maintaining discipline when refactoring
  • Common smells found in legacy code, and refactoring techniques for removing them
  • Using automated tests to support refactoring

In this chapter we’ll look at your most important weapon in the fight against legacy, namely refactoring. I’ll introduce some general tips for effective refactoring, as well as a few specific refactorings that I often use in real-world code. We’ll also look at techniques for writing tests for legacy code, which is vital if you want assurance that your refactoring work hasn’t broken anything.

4.1. Disciplined refactoring

Before we start looking at specific refactoring techniques, I want to talk about the importance of ...

Get Re-Engineering Legacy Software now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.