Long Parameter List

A function with too many arguments.

“The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided where possible.” – Robert C. Martin

Signs of Use (Symptoms)

  • Function takes more than 3 arguments.
  • Arguments are added to an existing function as requirements grow.
  • Many boolean “flag” arguments.

Why it is bad (Consequences)

  • Readability: Hard to remember argument order.
  • Error Prone: Easy to swap arguments of the same type.
  • Testability: Requires many permutations of inputs.

Why it happens (Root Cause)

Adding a parameter is faster than refactoring to use an options object or breaking the function.

When it might be okay (Exceptions)

  • Well-known standard APIs (e.g., Math.pow(x, y)).

Explanation

Problem

A function started with 2 parameters. Ticket by ticket, it grew to 8.

The Flaw

Cognitive overload. You must remember the meaning and order of each argument.

Real world analogy

A form with 50 fields on one page. Break it into sections/tabs.

Refactoring Solution

  • Introduce Parameter Object: Group related params into an object.
  • Preserve Whole Object: Pass an object that already holds the data.

Pros and Cons (of the Antipattern)

Pros (Why people do it) Cons (The price you pay)
  • Explicit
  • Hard to read
  • Easy to make mistakes
  • Comparison

    • Related Antipatterns: Data Clumps.
    • Related Principles: None directly.

    Code example

    Typescript

    Bad (The Antipattern)

    Good (The Fix)

    PHP

    Bad (The Antipattern)

    Good (The Fix)