Refactoring
Martin Fowler's book on changing the structure of code without changing its behaviour, through small, safe, named steps. The second edition (2018) uses JavaScript examples and describes about seventy refactorings. It is for developers who keep rewriting code in risky big bangs and want the habit of improving it in steps small enough that nothing breaks.
2nd edition, 2018
martinfowler.com · Sept 2026
About 70
martinfowler.com · Sept 2026
JavaScript
martinfowler.com · Sept 2026
4.24/5 (8,881 ratings)
Goodreads · Sept 2026
Book
Other
Martin Fowler
Intermediate
around $45
What the book is
Refactoring defines the practice most developers now take for granted: improving the internal design of existing code through small behaviour-preserving transformations, each backed by tests. The second edition, published in 2018, rewrote the examples in JavaScript (the 1999 first edition used Java) and describes around seventy refactorings in detail: the motivation for each, the mechanics of doing it safely, and a simple example. Fowler has called it the book he is proudest of for its impact on software development.
On Goodreads the book averages 4.24 out of 5 from about 8,900 ratings on its main listing (September 2026).
The part everyone should read
The first few chapters are the heart of the book:
- A worked example that takes a messy function and refactors it step by step, running tests after each move. Watching the process is more valuable than any individual technique.
- Principles: what refactoring is and is not, when to do it (the "rule of three", preparatory refactoring before adding a feature), and how it relates to performance.
- Bad smells in code: the list of symptoms that suggest a refactoring, such as long functions, duplicated code, feature envy, data clumps and primitive obsession.
- Building tests: why a refactoring without tests is just editing.
Read these even if you never open the catalogue.
How to use the catalogue
The rest of the book is a reference: Extract Function, Inline Variable, Move Function, Replace Conditional with Polymorphism, Split Phase and many more. Do not read it straight through. When you notice a smell in your own code, look up the matching refactorings and follow the mechanics precisely. Most modern IDEs automate the common ones, but knowing the names helps you talk about changes in code review.
Buying the book also gives access to a web edition with additional material; the author's site explains how to access it.
Is it worth it?
Yes, for developers with some real code of their own to improve. It changes how you work: instead of rewriting a messy module in one go and hoping, you make a series of small steps, each leaving the code working. That habit makes you safer and faster on any team.
If you are just starting to program, it will feel abstract. Come back once you have a project that has grown uncomfortable. For a free, illustrated introduction to the same smells and techniques, Refactoring.Guru is a good first step before the book.
Common questions
First or second edition? Get the second. The ideas are the same, but the examples and catalogue are updated.
I do not write JavaScript. Does it matter? Very little. The examples are simple and the techniques apply to any language.
Pair it with: Working Effectively with Legacy Code, for getting tests around code before you refactor it.
Best for: developers with a year or more of experience who want a disciplined, low-risk way to improve existing code.
Ready to start?
Opens on Martin Fowler in a new tab.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
Follow along
New writing, resources and project ideas land here first.