Skip to content

Long Parameter List

How to spot functions that take too many positional arguments, especially boolean flags, and the refactorings that make their call sites readable again.

6 min readCode smellBloat

A long parameter list is a function signature that has grown until callers can no longer read a call and know what it does. Five, eight, eleven positional arguments, several of them true or false, and a call site that looks like build("ORD-1", "dhl", 1450, 30, 20, 12, true, 0, false, true, false). The smell rarely appears all at once. Each new requirement adds one more argument because that is the smallest change that works today. Over a year the function becomes a switchboard, and every caller has to know the exact order and meaning of every slot, including the ones it does not care about.

Signs

How to spot it in a review.

  • A call site where you have to count commas or open the definition to know which number is which.
  • Two or more boolean arguments next to each other, so a call reads true, false, true.
  • Groups of parameters that always travel together, such as length, width and height, or amount and currency.
  • Parameters that only matter when another parameter has a particular value, like a declared value that is ignored unless insured is true.
  • Callers that pull several fields out of one object just to pass them back in separately.
  • Most callers passing the same default for half the arguments.

What it looks like

A typical case, in three languages.

type LabelRequest = {
  reference: string;
  carrier: string;
  billableGrams: number;
  dimensionsCm: [number, number, number];
  services: string[];
};

export function buildLabelRequest(
  orderId: string,
  carrier: string,
  weightGrams: number,
  lengthCm: number,
  widthCm: number,
  heightCm: number,
  insured: boolean,
  declaredValueCents: number,
  signatureRequired: boolean,
  saturdayDelivery: boolean,
  isReturn: boolean,
): LabelRequest {
  const volumetricGrams = Math.ceil((lengthCm * widthCm * heightCm) / 5);
  const billableGrams = Math.max(weightGrams, volumetricGrams);

  const services: string[] = [];
  if (insured) services.push(`INSURANCE:${declaredValueCents}`);
  if (signatureRequired) services.push("SIGNATURE");
  if (saturdayDelivery && !isReturn) services.push("SATURDAY");

  return {
    reference: isReturn ? `RET-${orderId}` : orderId,
    carrier: carrier.toUpperCase(),
    billableGrams,
    dimensionsCm: [lengthCm, widthCm, heightCm],
    services,
  };
}

// In the fulfilment worker:
const request = buildLabelRequest("ORD-88213", "dhl", 1450, 30, 20, 12, true, 12900, false, true, false);
console.log(request);

This is a shipping-label builder from a warehouse service. Eleven positional arguments, four of them booleans. Swap 30 and 20 and nothing fails, yet the label is wrong. Swap the last three booleans and a return parcel gets Saturday delivery logic applied. declaredValueCents is meaningless unless insured is true, and isReturn changes the reference format, so the function really does two jobs. Length, width and height always travel together and deserve their own type.

Why it happens

How code ends up like this.

  • Every positional argument is a slot the caller must fill in the right order, and type checkers cannot catch two swapped values of the same type.
  • Boolean flags hide intent: true, false, true tells a reader nothing, and each flag doubles the number of behaviours the function can take.
  • Parameters that always appear together signal a missing concept, such as parcel dimensions or a money amount, that would otherwise own its own validation.
  • Adding one more argument forces a change at every call site, so the signature becomes expensive to evolve and people start adding defaults to avoid the pain.
  • Long lists often mean the function does several jobs, which makes it harder to test each path in isolation.

Treatment

The refactorings that cure it, and when to choose each.

Payoff

What you get once it's gone.

  • Call sites read like a description of the parcel instead of a row of anonymous values.
  • Swapped arguments become compile-time or construction-time errors rather than wrong labels in production.
  • New options can be added to a parameter object without touching every caller.
  • Concepts like dimensions and insurance get one home for their validation and calculations.
  • Each behaviour, such as outbound versus return labels, can be tested on its own.

When to leave it

Sometimes it's not worth fixing.

  • Small, private helpers with three or four clearly distinct parameters of different types are fine; wrapping them in an object adds ceremony without safety.
  • Functions that mirror an external API exactly, such as a thin wrapper over a library call, can keep that signature so the mapping stays obvious.
  • Mathematical functions where the order is conventional and well known, like clamp(value, min, max), do not need a parameter object.
  • If breaking the dependency would force a hidden coupling, such as passing a whole object to a module that should only see two fields, a few explicit parameters are the better trade.

Common questions

Short answers to the usual doubts.

How many parameters is too many?

There is no magic number. The real test is whether a reader can understand a call without opening the definition. Three well-named parameters of different types are usually fine. Two booleans in a row, or two numbers of the same unit next to each other, are already a risk even if the total count is low.

Don't named arguments in Python and PHP 8 solve this?

They help a lot at the call site, and making booleans keyword-only in Python is a cheap first step. They do not fix the underlying design: fields that belong together still lack a type, invalid combinations are still possible, and every new option still widens the signature. Treat named arguments as a mitigation, then look for the missing concept.

Is a parameter object just a way to hide the same number of arguments?

Only if you build it as a bag of unrelated fields. A good parameter object groups values that form a concept, validates them once, and attracts behaviour that used to live in the caller, like the volumetric-weight calculation on parcel dimensions. If no behaviour ever moves onto it, reconsider the grouping.

Why are boolean flags singled out?

A boolean argument means the function has at least two code paths, and the call site gives no hint which one runs. Several flags multiply the paths and the test cases. Splitting the function or replacing the flag with an enum or a dedicated method makes the chosen behaviour visible where it is invoked.

How would you explain this smell in an interview?

Name the risk first: silent argument swaps and unreadable call sites. Then show the fix in steps on a concrete function: group related values with a parameter object, pass whole objects the caller already has, remove flag arguments by splitting behaviour, and use an options object or builder for the long tail. Mention when you would leave it alone, which shows judgement.

Next guide4 of 5 · Smells: bloatPrimitive Obsession: when strings and numbers fake domain conceptsRead the next one