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
insuredis 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);import math
def build_label_request(
order_id: str,
carrier: str,
weight_grams: int,
length_cm: int,
width_cm: int,
height_cm: int,
insured: bool,
declared_value_cents: int,
signature_required: bool,
saturday_delivery: bool,
is_return: bool,
) -> dict:
volumetric_grams = math.ceil((length_cm * width_cm * height_cm) / 5)
billable_grams = max(weight_grams, volumetric_grams)
services: list[str] = []
if insured:
services.append(f'INSURANCE:{declared_value_cents}')
if signature_required:
services.append('SIGNATURE')
if saturday_delivery and not is_return:
services.append('SATURDAY')
return {
'reference': f'RET-{order_id}' if is_return else order_id,
'carrier': carrier.upper(),
'billableGrams': billable_grams,
'dimensionsCm': [length_cm, width_cm, height_cm],
'services': services,
}
# In the fulfilment worker:
request = build_label_request('ORD-88213', 'dhl', 1450, 30, 20, 12, True, 12900, False, True, False)
print(request)<?php
function buildLabelRequest(
string $orderId,
string $carrier,
int $weightGrams,
int $lengthCm,
int $widthCm,
int $heightCm,
bool $insured,
int $declaredValueCents,
bool $signatureRequired,
bool $saturdayDelivery,
bool $isReturn
): array {
$volumetricGrams = (int) ceil(($lengthCm * $widthCm * $heightCm) / 5);
$billableGrams = max($weightGrams, $volumetricGrams);
$services = [];
if ($insured) {
$services[] = "INSURANCE:{$declaredValueCents}";
}
if ($signatureRequired) {
$services[] = 'SIGNATURE';
}
if ($saturdayDelivery && !$isReturn) {
$services[] = 'SATURDAY';
}
return [
'reference' => $isReturn ? "RET-{$orderId}" : $orderId,
'carrier' => strtoupper($carrier),
'billableGrams' => $billableGrams,
'dimensionsCm' => [$lengthCm, $widthCm, $heightCm],
'services' => $services,
];
}
// In the fulfilment worker:
$request = buildLabelRequest('ORD-88213', 'dhl', 1450, 30, 20, 12, true, 12900, false, true, false);
print_r($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, truetells 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.
- Introduce Parameter Object: Bundle Parameters That Travel Together
Several parameters always travel together, like length, width and height. Group them into a
ParcelDimensionstype that can also own the volumetric-weight calculation. - Preserve Whole Object: Pass the Object, Not Its Fields
The caller already has an
OrderorParcelobject and is unpacking its fields only to pass them in one by one. Pass the object instead. - Remove Flag Argument: Replace a Boolean with Explicit Functions
A boolean switches between two distinct behaviours, like
isReturn. Split it intobuildLabelRequestandbuildReturnLabelRequestso callers name the behaviour they want. - Replace Primitive with Object: Give Rule-Bearing Values a Type
A pair of primitives only makes sense together, such as
insuredplusdeclaredValueCents. Replace them with an optionalInsurancevalue so the invalid combinations cannot be expressed. - Change Function Declaration: Fix a Signature Without Breaking Callers
The remaining optional extras, like signature and Saturday delivery, are best passed as a single named options object so call sites read as labelled settings.
- Replace Function with Command: Turn a Long Function into an Object
The list keeps growing and callers configure the request in several steps. Move the logic into a builder or command object with named setters and a final
build().
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.