Code smell 2026-10-24
An observable feature of source code suggesting a possible underlying design problem. It prompts investigation rather than proving a defect. Duplicate code, feature envy and a long method suggest potential transformations, and context can justify leaving an apparent smell unchanged.[ref]
A software engineer and author writing about refactoring and software design. His short essay Code Smell by Martin Fowler explains the distinction between noticing a symptom and establishing the design problem behind it.
Figure 1.
Martin Fowler speaking in 2015
. Photograph by Webysther Nunes, at the Institute of Mathematics and Statistics of the University of São Paulo. CC BY-SA 4.0. Source.
A code smell is an easily noticed feature that suggests a deeper design problem worth investigating. It is neither a proven bug nor an automatic instruction to rewrite the code. Context determines whether the symptom is troublesome.[ref]
Duplicate code can indicate that the same knowledge has several maintenance sites: a correction made to one copy may be forgotten in the other. If the copies represent the same responsibility, extract that responsibility into one shared operation or component. Merely looking similar is insufficient; accidentally similar code with independent purposes should not necessarily be coupled.
Feature envy occurs when an operation depends mainly on another object's data rather than the responsibilities of its own class. For example, an editor view might implement a text-policy decision by repeatedly inspecting document internals. Move that decision to the document, or extract and move the relevant part, so behavior sits with the data and responsibility it actually uses. Duplication suggests consolidating repeated knowledge; feature envy suggests moving a responsibility between objects. These are different design actions, and both can be refactorings that preserve observable behavior.[ref]