Rule
Use descriptive variable names.
Very short variable names make code unclear.
Supported languages: 45+Introduction
Single-letter or cryptic variable names force readers to deduce meaning from context instead of understanding code at a glance. A variable named d could represent date, duration, distance, or data, requiring mental effort to track its purpose throughout the function. Descriptive names like userCreatedDate or requestDuration make intent immediately clear without cognitive overhead.
Why it matters
Code maintainability: Unclear variable names slow down comprehension. Developers spend time figuring out what x, tmp, or val represent instead of focusing on the actual logic. Poor naming also makes code harder to extend because it’s unclear where new logic should fit or how existing values relate to each other. On top of that, vague names make the codebase unsearchable, since searching for tmp or val gives no meaningful results. This compounds when returning to code months later or when new team members join.
Bug introduction: Ambiguous names increase the chance of using the wrong variable. When multiple variables have similar cryptic names (d1, d2, d3), developers might use the wrong one, introducing subtle bugs that pass code review because the names provide no semantic clues.
Code examples
❌ Non-compliant:
function calcAmt(u, qty) {
const p = u.prc;
const d = u.disc || 0;
const t = p * qty;
const a = t - (t * d);
const tx = a * 0.08;
return a + tx;
}
Why it's innacurate: Variable names like u, p, d, t, and a reveal nothing about their purpose. Readers must trace through the calculation logic to understand that p is price, d is discount, t is subtotal, and a is amount before tax.
✅ Compliant:
function calculateOrderAmount(product, quantity) {
const price = product.price;
const discount = product.discount || 0;
const subtotal = price * quantity;
const amountAfterDiscount = subtotal - (subtotal * discount);
const tax = amountAfterDiscount * 0.08;
return amountAfterDiscount + tax;
}
Why this matters: Each variable name describes what it contains. amountAfterDiscount clearly indicates the calculation state, tax is unambiguous, and product and quantity reveal the function's inputs without needing to read the body.
Conclusion
Use names that reveal intent without requiring context. Favor clarity over brevity. The extra characters in totalPrice versus tp cost nothing in execution but save significant time in comprehension.
.avif)
