Code Smell 10 - Too Many Arguments
Objects or Functions need too many arguments to work
Problems
Low maintainability
Low Reuse
Coupling
Solutions
Find cohesive relations among arguments
Create a "context".
Consider using a Method Object Pattern.
Avoid "basic" Types: strings, arrays, integers, etc. Think on objects.
Exceptions
- Operations in real world needing not cohesive collaborators.
Sample Code
Wrong
Right
Detection
Most linters warn when the arguments list is too large.
Tags
- primitive
Conclusion
Relate arguments and group them. Always favor real world mappings. Find in real world how to group the arguments in cohesive objects.
If a function gets too many arguments, some of them might be related to the class construction. This is a design smell too.
Relations
Credits
Photo by Tobias Tullius on Unsplash
This article is part of the CodeSmell Series.
No Comments Yet