Code Smell / Bad Smell
A code smell a.k.a. bad smell is a hint that something has gone wrong somewhere in our code.
Smells are certain structures in the code that indicate violation of fundamental design principles and negatively impact design quality.
Code smells are usually not bugs — they are not technically incorrect and do not currently prevent the program from functioning.
Instead, they indicate weaknesses in design that may be slowing down development or increasing the risk of bugs or failures in the future.
Determining what is and what is not a code smell is subjective and varies by language, developer and development methodology.
There are tools, such as Checkstyle, PMD and FindBugs for Java to automatically check for certain kinds of code smells.
Common code smells are as follows:
Application-level smells
- Duplicate code
- Contrived complexity — forced usage of over complicated design patterns where simpler design would suffice
Class-level smells
- Large class
- Feature envy — a class uses methods of another class excessively
- Cyclomatic complexity — too many branches or loops which may indicate a function needs to be broken up into smaller functions
Method-level smells
- Too many parameters
- Long method
- Excessive return of data