Cover of Refactoring by Martin Fowler, Kent Beck - Business and Economics Book

From "Refactoring"

Author: Martin Fowler, Kent Beck
Publisher: Addison-Wesley Professional
Year: 1999
Category: Computers

🎧 Free Preview Complete

You've listened to your free 10-minute preview.
Sign up free to continue listening to the full summary.

🎧 Listen to Summary

Free 10-min Preview
0:00
Speed:
10:00 free remaining
Chapter 2: Principles in Refactoring
Key Insight 1 from this chapter

Definition and Core Principles of Refactoring

Key Insight

Refactoring, precisely defined, is either a noun—'a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior'—or a verb—'to restructure software by applying a series of refactorings without changing its observable behavior.' This means a two-hour refactoring session could involve dozens of individual, smaller refactorings, such as 'Extract Function' or 'Replace Conditional with Polymorphism.' Critically, refactoring specifically implies applying small, behavior-preserving steps, contrasting with general code cleanup or restructuring.

The essence of refactoring lies in its behavior-preserving nature, meaning the code should fundamentally do the same things as before, even if internal mechanisms like the call stack change. This allows developers to stop at any moment without the code being in a broken state, differentiating it from scenarios where code is non-functional for days during a cleanup. While refactoring alters internal interfaces, like 'Change Function Declaration' or 'Move Function', the overall user-observable functionality remains constant, and existing bugs should persist.

Refactoring differs from performance optimization primarily in its purpose. Refactoring aims to make code 'easier to understand and cheaper to modify,' potentially affecting speed positively or negatively. In contrast, performance optimization solely prioritizes speeding up a program, even if it results in code that is harder to work with. The 'Two Hats' metaphor suggests distinct activities: adding functionality involves adding tests and making them work, while refactoring focuses purely on restructuring code without adding new features or tests (unless a missed case is found or an interface changes).

📚 Continue Your Learning Journey — No Payment Required

Access the complete Refactoring summary with audio narration, key takeaways, and actionable insights from Martin Fowler, Kent Beck.