Skip to content
aipatterns.dev

Refactoring techniqueSimplifying Method Calls

Remove Parameter

Delete a parameter the method body no longer uses, updating every caller and override so the signature states only real dependencies.

Also known as
Change Function Declaration

Problem

A method takes a parameter it ignores. It was used once, or added "in case", and now every caller has to compute and pass a value that changes nothing. Readers assume it matters.

Solution

Remove the unused parameter from the method and from every call site.

Before

TypeScript
function scheduleReminder(
  appointment: Appointment,
  leadMinutes: number,
  timezone: string, // unused since reminders moved to UTC
  channel: "sms" | "email",
): Job {
  const runAt = new Date(appointment.startsAt.getTime() - leadMinutes * 60_000);
  return queue.enqueue("reminder", { appointmentId: appointment.id, channel }, runAt);
}

scheduleReminder(appt, 60, clinic.timezone, "sms");

After

TypeScript
function scheduleReminder(
  appointment: Appointment,
  leadMinutes: number,
  channel: "sms" | "email",
): Job {
  const runAt = new Date(appointment.startsAt.getTime() - leadMinutes * 60_000);
  return queue.enqueue("reminder", { appointmentId: appointment.id, channel }, runAt);
}

scheduleReminder(appt, 60, "sms");

Why

  • A signature is a contract. Every parameter in it claims the method depends on that value.
  • Callers stop computing values that are thrown away, which sometimes removes whole lookups.

Steps

  1. Confirm the parameter is unused in the body and in every override and implementation. A parameter unused in the base class may be used in a subclass.
  2. If the method is overridden or implements an interface, change all declarations together.
  3. If your tooling has a safe "change signature" refactoring, use it. Run the tests.
  4. Otherwise create a new method without the parameter, make the old one delegate to it, and move callers over a few at a time. Run the tests after each batch.
  5. Delete the old signature when nothing calls it.

Watch out

  • Do not remove a parameter required by an interface, callback type or framework hook (Express middleware next, event handler signatures). Prefix it with _ to signal it is intentionally unused.
  • Positional removal in JavaScript shifts later arguments. Callers passing values by position will send the wrong value into the wrong slot without a type error if the types match. Use the type checker, and update all callers in one change.
  • Public APIs need a deprecation period. Keep an overload that accepts and ignores the old argument.
  • Check whether computing the argument had side effects at the call site that callers still rely on.
  • The inverse technique is Add Parameter.

Agent checklist

  • The parameter is unused in every override and implementation.
  • It is not required by an external interface, callback type or framework.
  • All positional callers were updated in the same change.
  • Argument expressions removed from call sites had no side effects callers depend on.

Treats these smells

See also

Original writing and examples. Topic coverage follows Refactoring.Guru, which explains this topic with its own illustrations.