From "Refactoring"
🎧 Listen to Summary
Free 10-min PreviewFoundational Concepts of Code Smells and Refactoring
Key Insight
The ability to identify 'when' to refactor is as critical as understanding 'how' to perform the mechanical steps. This strategic decision-making involves recognizing 'code smells,' a metaphor developed to describe structures within code that suggest a need for improvement. These 'smells' offer a more concrete basis for refactoring decisions compared to vague notions of programming aesthetics, having been identified through extensive analysis of diverse software projects, from highly successful to nearly dead.
Effective refactoring relies primarily on informed human intuition, rather than rigid sets of metrics. While precise criteria for refactoring are not provided, the text offers indications of potential trouble spots that can be resolved through refactoring. Developers are encouraged to cultivate their own judgment regarding excessive elements, such as the number of instance variables or lines of code within a method, as this discernment is deemed superior to automated measures.
This chapter, alongside a companion table, functions as a practical source of inspiration when the specific refactoring needed is unclear. The recommended process is to first identify the detected 'smell' within the code, then consult the suggested refactorings to assess their potential helpfulness. Even if an exact match for the observed 'smell' isn't explicitly listed, the provided guidance is designed to direct the developer towards an appropriate and beneficial refactoring direction.
📚 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.