Library Discover Ideas My library Paths Compare Shelves Collections Method
RefactoringMartin FowlerCover of Refactoring by Martin Fowler
4 min read

Technology & AI

Refactoring

Martin Fowler

Martin Fowler's catalogue of disciplined transformations that improve the internal structure of code without changing what it does — and the argument that this is a routine daily activity rather than a project someone has to approve.

First published
2012
Publisher
Pearson Education, Limited
Pages
461
Level
Deep
ISBN-13
9780321604187
softwaredesignreference

Record checked against

Only one source carried a publication date for this work, so the year is uncorroborated.

Catalogue note

Reads as
ReferenceBuilt to be consulted rather than read straight through.
Level
Advanced / AdvancedAssumes you have read around the subject already.
Approach
Practical
Written for
Engineers, Specialists and serious readers
Your shelf

Saved in this browser only — no account, nothing sent anywhere. My library

Read this if

  • You build software and want the ideas under the tools.
  • You care why some things are obvious to use and others are not.
  • You want something to keep nearby and return to, rather than read once.
  • You have read around this already and want a book that assumes it.
01

The definition is the discipline

Fowler's definition is precise and load-bearing: refactoring is a change to the internal structure of software that makes it easier to understand and cheaper to modify **without changing its observable behaviour**.

Everything follows from that last clause. A change that alters behaviour is not refactoring, however tidy the result — and the distinction matters because it determines whether you are allowed to do it without asking.

If behaviour changes, it is not refactoring. That clause is what makes it safe to do continuously.

Devmark’s reading — not a quotation from the book
02

The two hats

Fowler's rule for practice: when you work on code you wear one of two hats. Adding a feature means not changing existing structure. Refactoring means not adding functionality and not writing tests.

Swapping frequently is fine; wearing both at once is not, because a bug then has two possible sources and the safety of the operation collapses. This single discipline is the most useful thing in the book.

03

Small steps, always green

The method is a sequence of transformations so small that each is obviously correct, with the tests run after each one.

Fowler is explicit that steps that feel absurdly small are the point: their value is that when something breaks you know exactly which change did it. The habit is harder to adopt than it sounds, because experienced programmers want to make the whole change at once.

04

Tests are the precondition

Refactoring without adequate tests is not refactoring; it is editing and hoping. Fowler is unambiguous that a reliable test suite is what makes the whole practice possible.

The chapter on building tests is therefore not an aside but a prerequisite, and it contains the useful advice to write tests focused on risk rather than on coverage — testing the parts most likely to break rather than pursuing a percentage.

05

Code smells

Written with Kent Beck, the catalogue of smells is the book's most-cited contribution: duplicated code, long function, large class, long parameter list, divergent change, shotgun surgery, feature envy, data clumps, primitive obsession, and others.

Fowler is careful that a smell is an indication rather than a rule — a prompt to look, not a defect to fix. Treating the list as a linter is a misreading, and a common one.

06

The catalogue

The bulk of the book is a reference of named refactorings, each with a motivation, a mechanics section of numbered steps, and a worked example.

The naming is itself a contribution. Once Extract Function, Move Field, Replace Conditional with Polymorphism and Introduce Parameter Object have names, a team can discuss a change in one phrase instead of describing it — and most modern IDEs implement them by those names.

Naming the transformations is what let teams discuss structural change in a phrase instead of a paragraph.

Devmark’s reading — not a quotation from the book
07

When not to refactor

Fowler is more balanced here than his reputation suggests. Do not refactor code you are about to delete. Do not refactor when a rewrite is genuinely cheaper. Do not start a large refactoring close to a deadline, because the safety comes from finishing.

His preferred model is opportunistic — the camp-site rule of leaving code better than you found it — over scheduled refactoring projects, which tend to be cancelled halfway and leave the code worse than either state.

08

What the second edition changed

The 2018 edition rewrote the examples in JavaScript rather than Java, which broadened the audience and shifted the emphasis away from class-centred transformations.

It also reorganised the catalogue, added refactorings for function-oriented code, and reflected two decades of tooling in which many of these are now a keystroke. The argument is unchanged; the demonstration is more widely legible.

09

Where it is limited

It is a reference book and reads like one. The catalogue is not designed to be read straight through, and readers who try usually stop.

It also says comparatively little about refactoring across service boundaries, about database schema evolution in production, or about the organisational question of how a team creates the space to do any of this — all of which are where the difficulty actually lives in large systems.

10

Why it matters

Because it made structural improvement a normal activity rather than a special request. Before the vocabulary existed, changing code that already worked required justification; after it, "I refactored it" is a complete sentence.

Its most durable contribution is the pairing of discipline and permission: because refactoring by definition does not change behaviour, and because the steps are small and test-verified, it is something a professional can simply do.

—

What to take away

  1. 01Behaviour must not changeThat clause is what makes refactoring safe to do continuously and without approval.
  2. 02Wear one hat at a timeAdding features and restructuring simultaneously means a bug has two possible sources.
  3. 03Steps too small to be wrongThe value of an absurdly small step is that a failure identifies its own cause.
  4. 04Smells are prompts, not defectsThe catalogue is an invitation to look, and treating it as a linter is the common misreading.
  5. 05Prefer opportunistic to scheduledLarge refactoring projects get cancelled halfway and leave the code worse than either end state.

Reading journey

A route through this idea

This book is not on a curated path, so the route below is derived from the catalogue: what comes before it, what goes further, and what approaches the same ground differently.

  1. Start hereA Philosophy of Software DesignComputing and Design, and it assumes less before you start.
  2. You are hereRefactoring
  3. A different angleDesigning Data-Intensive ApplicationsAlso about Computing, but it reads as technical where that one is reference.
  4. Somewhere else entirelyAmp It UpManagement and Computing travel together in this library, and this comes at it from the other side.

Nearby on the shelves

Related reading

↑↓ to move↵ to openesc to close