Code Smell 03 — Functions Are Too Long
Humans get bored beyond line 10.
Published in
Oct 22, 2020
Problems
- Low Cohesion
- High coupling
- Difficult to read
Solutions
1) Refactor
2) Create small objects dealing with some of the tasks. Unit test them.
3) Compose methods
Examples
- Libraries
Sample Code
Wrong
Right
Detection
All linters can measure and warn when methods are larger than a predefined threshold.
Also Known as
- Long Method
More info
Tags
- Complexity
Programs are meant to be read by humans and only incidentally for computers to execute.
Donald Knuth
This article is part of the CodeSmell Series.