02
Inline Function
Goal
Trivial wrappers vanish; the call site reads as exactly what's happening.
Before the refactoring
function getRating(driver) {
return moreThanFiveLateDeliveries(driver) ? 2 : 1;
}
function moreThanFiveLateDeliveries(driver) {
return driver.numberOfLateDeliveries > 5;
}After the refactoringfunction getRating(driver) {
return driver.numberOfLateDeliveries > 5 ? 2 : 1;
}Savings
One fewer indirection to follow when reading; smaller surface to maintain.
Note
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.