Inline Function

Referenced by patterns
Symptom

A function whose name is no clearer than its body — wrappers that add no semantic value (`moreThanFive(n) { return n > 5 }`), pass-through functions called only once, or thin abstractions over trivial expressions. The reader's rises because every hop to the wrapper pays a name lookup that returns no domain meaning.

Goal

Trivial wrappers vanish; the call site reads as exactly what's happening, lifting the of the file. Readers see the operation rather than a name that just renames a primitive; the file shrinks by one definition per inline, and the call site carries the meaning that the wrapper's name failed to convey.

Before the refactoring

function moreThanFive(n) {
return n > 5;
}
function rating(driver) {
return moreThanFive(driver.numberOfLateDeliveries) ? 2 : 1;
}

After the refactoring

function rating(driver) {
return driver.numberOfLateDeliveries > 5 ? 2 : 1;
}
Example source: Illustrative example written for this site; the refactoring itself is catalogued in Martin Fowler's Refactoring (Addison-Wesley, 2018), see the chapter on A First Set of Refactorings.
Pressure

Readers pay a hop to look up the wrapper only to find it adds nothing; the indirection crowds the file with definitions that don't earn their keep. The team's compounds across every reviewer who follows the hop to confirm it really does no work, and the wrapper's name adds noise that competes with real domain vocabulary.

Tradeoff

If the function had a meaningful name covering several call sites, inlining can scatter the intent — only inline when the body is as clear as the wrapper. The team's can rise rather than drop if inlining strips a name that was load-bearing across multiple sites, because the original named concept now lives nowhere.

Relief

One fewer indirection to follow when reading; smaller surface to maintain. The team's drops because adding a new variant doesn't require updating the wrapper's signature, and the call site can grow inline without needing to reshape a wrapper that wasn't carrying meaning. Tests target the call site directly rather than the trivial helper.

Trap

Inlining wrappers that genuinely add meaning — `isOverdue(invoice)` is clearer than `invoice.dueDate < today()` even if mechanically identical — strips the named domain concept. The team's rises across every call site that now displays mechanism instead of intent, adding to readers who must re-derive the named concept on each read.