Naming Things
Practical rules for naming variables, functions and types so code reads like prose.
~1 min read updated Jul 17, 2026 Clean Code
#clean-code #naming #readability #craft
There are two hard things in computer science; this note is about one of them. Good names are the cheapest documentation you'll ever write.
Reveal intent
A name should answer why something exists and how it's used — without a comment.
// Unclear
const d = 30
const list = users.filter(u => u.a)
// Clear
const maxRetryDelaySeconds = 30
const activeUsers = users.filter(user => user.isActive)
Booleans read as yes/no questions
Prefix with is, has, can or should so conditions read naturally.
if (user.isVerified && cart.hasItems && payment.canProceed) {
// ...
}
Functions are verbs; values are nouns
| Kind | Style | Example |
|---|---|---|
| Function | verb phrase | calculateTotal, sendInvite |
| Boolean | predicate | isEmpty, hasAccess |
| Collection | plural noun | orders, activeUsers |
| Single value | singular noun | order, currentUser |
Avoid noise words
Manager, Data, Info, Object and Helper usually add length without
meaning. UserData is rarely clearer than User.Match the length to the scope
A loop index living for two lines can be
i. A module-level constant that other
files import deserves a full, descriptive name. Short scope, short name; long
scope, long name.