
Naming Things in Programming: A Practical Guide to Good Names
You may know the old joke. There are two hard problems in computer science:
- Cache invalidation.
- Naming things.
- Off-by-one errors.
It always gets a laugh. But the naming one is real. Naming things in programming is hard because a name has to carry meaning in very few characters, and it has to stay true as the code changes. Good names are documentation that never goes out of date. Bad names are traps that everyone after you has to walk around.
We have all been there: data2, temp, handleStuff(). Let us turn the joke into something useful.
Why names matter so much
Code is read far more often than it is written. Every time someone reads your code, the names are the first thing they see. A good name answers questions before they are asked. A bad name creates questions that someone has to answer by reading every line.
Names also shape how we think. If a function is called process(), nobody knows what it should or should not do, so it grows into a function that does everything. If it is called calculateShippingCost(), its job is clear, and it is easy to notice when it starts doing too much.
In 2026 there is another reason: AI tools read your names too. An AI assistant uses names as strong hints about intent. Clear names lead to better suggestions. Vague names lead to vague code.
Simple rules for good names
Say what it is, not how it is stored
userList tells me the type. activeUsers tells me the meaning. Prefer meaning. The type is usually clear from the code or the editor anyway.
Use verbs for functions and nouns for data
Functions do things: sendInvoice(), parseDate(), isExpired(). Data is things: invoice, startDate, retryCount. This small rule makes code read almost like a sentence.
Make booleans read like questions
isValid, hasAccess, shouldRetry are clear. flag, check and status are not. A good boolean name makes an if statement easy to read out loud.
Include units and context
timeout is unclear. timeoutMs or timeoutSeconds is not. price might be fine, but priceInCents can save a costly bug.
Avoid vague words
Words like data, info, manager, handler, helper and stuff often hide what something really does. If you reach for one, ask "what exactly is this?" and use that answer instead.
Be consistent
If you call it customer in one place, do not call it client in another and user in a third. Pick one word for one idea, and use it everywhere. A short team glossary helps a lot.
Before and after examples
Here are a few common bad names and better options:
data2becomespreviousOrders.tempbecomesunsavedDraft.handleStuff()becomesapplyDiscountCode().doIt()becomessyncInventoryFromSupplier().xin a loop over users becomesuser.
Notice that the better names are sometimes longer. That is fine. A name should be as long as it needs to be to be clear, and no longer. Short names like i are fine for a tiny loop. They are not fine for something used across a whole file.
How to get better at naming things in programming
Naming is a skill, and like any skill it improves with practice. A few habits help:
- Rename freely. Modern editors make renaming safe. If a better name comes to you, use it.
- Name it after you understand it. If you cannot name a function, you may not yet know what it should do. That is a design signal, not a naming problem.
- Review names in code review. It is fair to comment on a name. It is one of the cheapest ways to improve a codebase.
- Write your naming rules down. Put them in your team guide or the instructions file your AI tools read, so humans and agents follow the same rules. I explain why in context engineering.
For more practical habits like these, see my top JavaScript tips and my notes on front-end patterns and principles.
The takeaway
Naming things in programming will probably always feel hard. That is because a good name is a small piece of design. Say what it means, use verbs for actions, make booleans read like questions, include units, avoid vague words and stay consistent. Your future self, your teammates and your AI tools will all thank you.
If you want help improving code quality and conventions across your team, get in touch.
What is the worst variable name you have seen (or written)?
First shared on LinkedIn.
Subscribe to my newsletter
Read articles from Tech With Asim | Learn, Build, Lead directly inside your inbox. Subscribe to the newsletter, and don't miss out.
More Articles
Controlling LLM API Costs in Production: A Software Architect's Guide
As a software architect, managing costs for external LLM API usage in production is a critical part of building sustainable AI applications. The core…

AI Technical Debt: 5 Warning Signs and How to Prevent Them
AI can create tech debt faster than any human ever could. Five warning signs to watch for, and why the fix is shared review standards and written conventions, not less AI.

AI Pair Programming: Treat AI as a Partner, Not an Autopilot
Autopilot mode ships what you do not understand. Pair mode ships what you can explain. How to get the most from AI by treating it as a smart but sometimes wrong colleague.



Comments