A logbook for curious waters
← Software Engineering Field Guide

Add Parameter

Before you begin: Function declarations, arguments, and callers.

Add Parameter lets callers provide another piece of information to a function. It can expose an existing internal choice, remove dependence on hidden state, or prepare the function for a new requirement. Every caller must receive a deliberate migration, not an arbitrary value that merely makes the code compile. 1

Original version: the greeting chooses its own prefix

public static class Greetings
{
    public static string For(string name)
    {
        return "Hello, " + name;
    }
}
def greeting(name):
    return "Hello, " + name

All callers receive the same prefix. A harbor screen cannot request “Ahoy” without changing the function or rewriting the returned text.

Revised version: make the prefix an input

public static class Greetings
{
    public static string For(string name, string prefix)
    {
        return prefix + ", " + name;
    }
}
Console.WriteLine(Greetings.For("Mira", "Hello"));
Console.WriteLine(Greetings.For("Mira", "Ahoy"));

Existing callers preserve their result by supplying "Hello". A caller supplying "Ahoy" intentionally requests new behavior.

def greeting(name, prefix):
    return prefix + ", " + name
print(greeting("Mira", "Hello"))
print(greeting("Mira", "Ahoy"))

The old behavior is represented by an explicit argument rather than a hard-coded choice. The new variation belongs to the caller.

Separate the signature migration from the new feature

Changing every old call to pass the existing prefix can preserve current output. Introducing different prefixes is the feature change that the new signature enables. Keeping those steps distinct makes a failure easier to diagnose.

A default argument or compatibility overload can ease migration, but only when its meaning is unambiguous. In a public C# API, optional argument defaults are commonly embedded at compiled call sites; changing a default is not equivalent to changing a runtime lookup.

Also ask whether the callee should receive this value. Passing a whole application context just to obtain one setting can hide the real dependency, while adding many unrelated flags can make an API harder to understand. Prefer the smallest input that expresses what the operation genuinely needs.

Sources

  1. Martin Fowler — Change Function Declaration, including Add Parameter.
  2. Microsoft — Named and optional arguments.