Using descriptive names makes code self-explanatory, reducing the need for comments and making it easier to read and maintain.
🚨 Problems
Using short or cryptic names like vA
or tmp
may save a few keystrokes, but it increases the cognitive load for the reader — especially for those unfamiliar with the codebase.
Ambiguous abbreviations make code harder to understand and maintain, and often lead to misunderstandings or incorrect assumptions.
function calc(d, r) {
let t = d / r;
return t;
}
In the example above, it's unclear what d
, r
, or t
represent. This forces future readers to guess or trace logic unnecessarily.
âś… Solution
Use descriptive and intention-revealing names. The name should answer questions like:
“What does this function or variable represent?” or “What does it do?”
function calculateTravelTime(distance, rate) {
let time = distance / rate;
return time;
}
Avoid abbreviations unless they are universally understood (e.g. URL
, ID
), and try to make names as expressive as possible within reason.
💪🏽 Benefits
- Makes the code self-documenting, reducing the need for comments.
- Improves readability and comprehension, especially for new team members.
- Encourages consistency and better team collaboration.
- Reduces the risk of misinterpretation and bugs caused by unclear logic.