What is Code Smell?
A code smell is a surface indication that usually corresponds to a deeper problem in the system. Kent Beck first coined the term. It became popular after its appearance in Martin Fowler's book, Refactoring: Improving the Design of Existing Code. Code smells are subjective and vary based on developer, language, and methodology, among other factors.
It is an essential part of software development to find code smells, dig into the underlying causes and fix them via refactoring.
What are some frequently seen smells?
- Bloaters: This includes code, like methods and classes, that has become huge over time by accumulating functionality and feature creep.
E.g., long methods, god-classes, long parameter lists. - Dispensable: This refers to dead code, which is not being invoked or executed. These blocks of code are unnecessary, as they provide no benefits but increase technical debt.
E.g., duplicated code, refactoring artifacts, premature generalization. - Couplings: This means a code that should be independent ends up tied together because of excessive delegation or lack/absence of access control.
E.g., code forwarding, use of internal or private members.