Long Parameter List — Code Smells Catalog Skip to content

Long Parameter List

Bloaters Measured Smells AntipatternCode SmellDesign SmellImplementation Smell Within Class

Five arguments. Six. Seven. At some point the function signature becomes a riddle, the caller needs a cheat sheet, and the method is clearly trying to do more than one thing.

2 min read 1 source

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

Hard to Use

Usage of a method with many parameters requires more knowledge to use it.

🧩
Increased Complexity

The input value is highly inconsistent, which creates too much variety in what might happen throughout the execution.

Single Responsibility Principle Violation

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)
PYTHON

Refactoring

  • Replace Parameter with Query
  • Preserve the Whole Object
  • Introduce Parameter Object
  • Remove Flag Argument
  • Combine Methods into Class

Sources

Browse All 56 Smells