Overview
This is another code smell at the same abstraction level as Long Method which usually occurs when three, four, or more parameters are given as input for a single method. Basically, the longer the parameter list, the harder it is to understand.
Causation
In an attempt to generalize a routine with multiple variations, a developer could have passed too many parameters at one point. Another causation could be due to ignorance of the object relationship between other objects, and thus, instead, calling in all the entities via parameters [1].
Problems
Usage of a method with many parameters requires more knowledge to use it.
The input value is highly inconsistent, which creates too much variety in what might happen throughout the execution.
When there are too many parameters, most likely, the method tries to do too many things or has too many reasons to change.
Example
1def foo(author: str, commit_id: str, files: List[str], sha_id: str, time: str):
2 ...
3
4author, commit_id, files, sha_id, time = get_last_commit()
5foo(author, commit_id, files, sha_id, time)Refactoring
- Replace Parameter with Query
- Preserve the Whole Object
- Introduce Parameter Object
- Remove Flag Argument
- Combine Methods into Class
Sources
- ORIGIN1999 · ISBN 978-0201485677