03
Long Function
Symptom
Functions whose body has dozens of lines and a mix of concerns — fetching, calculating, formatting, and logging all interwoven.
Goal
Each function reads as a sequence of named single-responsibility steps; nothing does more than its name advertises.
Smellier version
function ship(order) {
if (!order.id) throw new Error('missing id');
const tax = order.total * 0.1;
const grand = order.total + tax;
email(order.user, `Total ${grand}`);
log(order);
}Fresher versionfunction ship(order) {
validate(order);
const grand = withTax(order);
notify(order, grand);
}Savings
Faster to read, easier to test, simpler to change one step without touching the others.
Note
Each line is an opportunity for the reader to lose context; understanding requires holding the whole function in working memory.