Refactoring

Improving the Design of Existing Code

by Martin Fowler

(with Kent Beck, John Brant, William Opdyke, and Don Roberts)

Refactoring is a controlled technique for improving the design of an existing code base. Its essence is applying a series of small behavior-preserving transformations, each of which "too small to be worth doing". However the cumulative effect of each of these transformations is quite significant. By doing them in small steps you reduce the risk of introducing errors. You also avoid having the system broken while you are carrying out the restructuring - which allows you to gradually refactor a system over an extended period of time.

My book describes the process of refactoring and spends most of its time explaining how to do the various refactorings - the behavior preserving transformations. The book opens with a simple example that describes the whole process. There are then some introductory chapters that discuss broader issues around refactoring, the "code smells" that suggest refactoring, and the role of testing.

The bulk of the book is around seventy refactorings described in detail: the motivation for doing them, mechanics of how to do them safely and a simple example.

The books finishes with some guest chapters from those whose early work have developed the ideas of refactoring.

This is the book that I'm proudest of, in that it's had a high impact on the world of software development. Several development environments now automate many of the refactorings described in the book. Refactoring has become a full-fledged part of the software development lexicon (sadly also leading to misuse).

A common question is whether the book is still relevant. After all it's over ten years old and technology has made many advances in that time. I'm firmly of the view that the book is still very useful. The refactoring techniques I describe have not changed, since they are part of the fundamental use of programming languages. Refactoring tools mean you don't always have to do them by hand, but it's still valuable to understand what the tool is doing. There are also many languages where you don't have tools, so knowing how to do it yourself is still important.

icon

Notes for buying my books

Errata

Translations: Japanese, German, Polish, Serbian, Portuguese, Chinese (Simplified and Traditional), Russian, Czech, and Korean

Further Reading

refactoring.com

Links to further resources on refactoring, including a catalog that includes summaries of all the refactorings in the book.