Return to site

CODE SMELL: The long parameter list 📏

· code-smell,coding

The long parameter list code smell 👃 happens when method signatures require long lists of parameters. They may include, among other things, flag 🚩 parameters, which are a specially bad 👎 pattern. Flag parameters are used solely to determine which conditional path the method must execute, and make it much harder to figure out the method's overall behavior and intention.

 

Why is it bad? 👎

Long parameter lists are harder 😫 to maintain. For example, making intermediary parameters optional is a specially difficult task to achieve in most languages.

If we pass parameters in the wrong 🔃order, we may very likely break 🔨 the function. It becomes increasingly difficult to figure out a function's invocation the longer its parameter list gets.

 

How to fix it? 💡

Substitute data parameters with a single data object 🎁 parameter.

If it's possible to obtain information about another parameter from a parameter, remove ❌ the additional parameter.

Avoid passing flag 🚩 parameters.