Skip to main content
CLEAN-CODE-PRINCIPLES5 MIN READ

Extract the function that explains the rule

Apply Extract Function to replace a what-comment with a named business rule.

A renewal function contains a comment that says check grace period, followed by a dense boolean expression. Reviewers keep re-parsing it when renewal rules change. Extract Function works best when the extracted name reveals the intention of a coherent rule. The common trap is extracting a mechanically selected chunk like checkDates or doRenewalStuff, which moves lines without improving the caller's language. Before // check renewal grace period if (sub.expiresAt > today && invoice.status !== 'blocked' && (region !== 'BR' || contract.overrideRenewal)) { renew(); } After if (isWithinRenewalGracePeriod(subscription, invoice, today)) { renew(); } function isWithinRenewalGracePeriod(subscription, invoice, today) { ... } Find…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us