Inline Function

Referenced by patterns
Compare
Symptom
Human

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.

Agent

A function whose body the agent traces through only to find no decisions or transformations — every reference site pays a hop for no reasoning gain. The agent's for the wrapper definition outweighs the information it returns, and the spent on the hop is pure overhead.

Goal
Human

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.

Agent

Trivial wrappers disappear from the agent's working context; call sites read as exactly what's happening. The agent's holds the call site without a wrapper hop; the of any edit drops because the agent doesn't load a definition only to confirm it does nothing surprising, and the file's signal-to-noise ratio improves.

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
Human

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.

Agent

The agent loads the wrapper definition to verify any change touching it; the indirection is a tax on every reasoning step. The agent's multiplies with the count of pass-through wrappers in the call chain, and the wrapper's body must be re-read on each edit to confirm it still does no domain work.

Tradeoff
Human

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.

Agent

Inlining scatters the wrapper's body across call sites; if the wrapper was a seam (mocking boundary, extension point), removing it forecloses a hook later edits cannot restore without re-extracting. The agent's rises during the inline itself — every call site must be confirmed to use the inlined form, and any remaining external reference becomes a regression.

Relief
Human

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.

Agent

Shorter call chains; the agent loads one fewer definition per reasoning step. The agent's per edit drops because the relevant body is at the call site, not in a separate file; verification surface contracts because there is no wrapper to confirm, and the file's signal-to-noise ratio rises as definitions that didn't earn their keep disappear.

Trap
Human

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.

Agent

Mechanically inlining every short function — including ones that name a real domain concept — collapses semantic anchors the agent uses to reason about behavior. The agent's reasoning-step cost actually rises per edit because the call site loses the named handle, and any subsequent edit must re-derive the concept the wrapper was naming.