Turn magic literals into policy names
Replace a magic literal with a named constant or policy object that communicates intent.
7 appears across a renewal flow. Some instances mean grace days; others mean retry count or dashboard columns. Replace Magic Literal when a value has domain meaning, change pressure, or ambiguity. The trap is creating SEVEN = 7, which names the primitive value but still hides the policy owner, unit, and reason for change. Before if (daysSinceExpiry <= 7) allowRenewal(); if (failedAttempts < 7) retryWebhook(); After if (daysSinceExpiry <= TRIAL_GRACE_PERIOD_DAYS) allowRenewal(); if (failedAttempts < WEBHOOK_RETRY_LIMIT) retryWebhook(); Classify the literal Ask whether the value is policy, unit conversion, protocol code, or incidental arithmetic. Only values with meaning need names. Name with…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in