Read Fowler's Refactoring before you touch a client's code
The book teaches a discipline that is easy to state and hard to keep: write the tests before you change anything, then change one small step at a time.

In brief
- The second edition of Martin Fowler's Refactoring, with contributions from Kent Beck, was published by Addison-Wesley on November 20, 2018, with examples in JavaScript.
- The core of the book is a catalog of about 70 refactorings, 15 of them new, each with a motivation, mechanics and an example.
- For FDEs the main value is the discipline: build tests first, move in small steps, and never leave a client's system broken.
Martin Fowler takes a blunt line on untested code: any non-trivial code without tests should be treated as broken. For an FDE who has just been given access to a client’s repository, that line should be a working rule.
FDE work rarely starts from a blank page. You usually have to change code someone else wrote, in a system running in production, while the client’s engineering team watches to see whether you break anything. For that situation, the second edition of Refactoring: Improving the Design of Existing Code is one of the most useful books to keep on your desk.
What is in the book?
The book is by Martin Fowler, with contributions from Kent Beck. It opens with a worked example that runs through the whole process, followed by foundational chapters on code smells and the role of tests, and then a catalog of about 70 refactorings, each with a motivation, step-by-step mechanics and an example.
The second edition merges some older refactorings: Add Parameter, Remove Parameter and Rename Method are now a single refactoring, Change Function Declaration. It comes up again below.
First idea: changing structure and changing behavior are separate jobs
By Fowler’s definition, refactoring changes the internal structure of software while preserving its externally observable behavior. That sounds obvious. On real projects, though, the two kinds of change often end up in the same pull request, and the client’s reviewer cannot tell which lines are cleanup and which change the results.
So the first habit worth learning is to separate them. One commit changes only structure; the tests stay the same and stay green. The next commit adds the feature the client asked for. The client’s team reviews faster, and when something goes wrong you know at once which commit to suspect.
Second idea: steps so small they are almost impossible to get wrong
Refactoring.com describes the heart of the technique as a series of small behavior-preserving transformations. Each step carries little risk, and the system keeps working after every one. The payoff is that you can stop anywhere without leaving the system half-finished.
Take a hypothetical example. The client’s code has a function calcInvoice(order, rate) called from 12 places, and you need to add a currency parameter. The hurried approach is to change the signature, fix all 12 call sites in one go and hope the build passes. Following Change Function Declaration, you move more slowly but far more safely.
Step one: create a new function that adds currency, with a default value of the current currency, make the old function call the new one, and run the tests. Step two: move the call sites to the new function one at a time, running the tests after each.
Final step: once nothing calls the old function, delete it. If the client pulls you into an urgent meeting after the fifth call site, the system still works correctly.
Third idea: no safety net, no changes
Every small step above is safe only if there are tests to run. Fowler calls this self-testing code, a term he uses in the book itself, and in his view that safety net is what gives you the time to keep code in good shape. The publisher also stresses that the book teaches how to build the tests you need before making changes.
Client code often has no such net. So the first job in an untested module is to write tests that record its current behavior, including behavior that looks wrong. You are simply capturing what the system does, so that every later change has something to be compared against.
The most common mistake happens at exactly this stage: while writing tests you spot what looks like a bug and fix it on the spot. Your test now records the behavior you want rather than the behavior that runs, and the results the client gets have changed without anyone approving it.
The right approach is to write tests that match current behavior, note the suspected bug, and raise it with the client as a separate behavior change. Another of their systems may depend on that very “bug.”
In what order should you read it?
If you have ever struggled with legacy code, the problems in the book will feel familiar from the first pages. Read the opening example carefully, then the chapters on code smells and testing. The testing chapter was rewritten entirely for the second edition, because the examples moved from Java to JavaScript.
Do not read the catalog of 70 refactorings cover to cover like a novel. Use it as a reference, alongside the online catalog Fowler maintains at refactoring.com/catalog/, when you hit the matching situation.
Teams working in JavaScript or TypeScript can apply it straight away. If you write Python or Java, the steps still work; you just translate the syntax yourself, and that translation helps it stick.
An interview question to rehearse
One question worth preparing before an FDE interview: “A client hands you a billing module with no tests, and they need a new feature this week. What do you do on day one?” A weak answer jumps straight into a redesign. A good answer follows the three ideas above.
First, you write tests that capture current behavior and note the suspected bugs to ask the client about. Then you refactor only the part the new feature will touch, in small steps and separate commits. The feature comes last, in a change the client can review on its own.
On your CV, describe that sequence through a specific time you did it, instead of the generic line “experienced in refactoring.” And if a take-home assignment hands you legacy code, tests for its current behavior should be your first commit.
Clients rarely remember the elegant code you left behind. They remember for a long time the day their system went down because of a change that was “just cleanup.”
Was this article useful?
Thanks for the feedback!
7 sources
- Refactoring: Improving the Design of Existing Code (martinfowler.com) · 2018
- Refactoring: Improving the Design of Existing Code, 2nd edition (Pearson) · 2018-11-20
- Refactoring.com
- Changes for the 2nd Edition of Refactoring (martinfowler.com)
- Self Testing Code (martinfowler.com)
- Refactoring Catalog (refactoring.com)
- Definition Of Refactoring (martinfowler.com)