Naming things correctly is understandably a serious task in programming. It is challenging because it is difficult to understand the characteristics of a good name. At the same time, this problem is so widespread, that developers would rather look at the actual code in a class than trust on what it’s name conveys.

From what I have learnt, there are 3 things that you should consider while naming your modules/ classes / variables in a meaningful way. Let’s take a look at them now!

1. Be Specific

Think of your best friend’s name, let’s say Lily as an example? Now what do you think defines her? Is she kind? Is she an introvert, quiet and thoughtful?

Now would you be able to name her only using her characteristics? Would KindIntrovert make sense? How about KindAndQuietHuman?

Obviously it’s hard to combine all the characteristics of a person into a single word.

If you need my attention but don’t know my name… yell “Nice Beard”, I’ll know you’re talking to me. Source: beardstyle.net

Now let’s consider the same for a class. Make a list of all the things it does and try to combine that into a single sensible name. If the name you come up with has a lot of different disconnected words like UserFetcherAndPermissionsUpdater, it’s a strong indication that your class is doing too many things (in this case fetching the user details and updating the permissions) and you should follow Single Responsibility Principle to reduce the number of things it does.

Remember, unlike humans, in software we have the freedom to limit the characteristics of the module that we are building.

2. Be Detailed

Let’s reconsider the previous example of a class with name UserFetcherAndPermissionsUpdater. Apart from handling multiple responsibilities, is there anything else that is wrong with the name?

Is it too long to type?

Would you rather name it UserAndPermissionsManager? How about UserPermissionsHelper?

The short answer is No. The more descriptive the name, the better & easier it is to understand the context. Terms like Manager obfuscate the responsibilities of the class and makes the class a dumping ground for more unrelated functionality in the future.

If you are short on time or in the middle of a deliverable, you may not always have time to refactor the class. But don’t be afraid of updating the class name to reflect what it truly does. The IDEs today have powerful autocompletion, so it’s not worth it to sacrifice context in lieu of short but vague names.

Long Names in fact make a strong case for revisiting the class and refactoring it as a part of reducing your technical debt.

3. Be Accurate

I touched this briefly in my last point, but don’t be afraid to proactively update the name of a class to reflect its current purpose. The nature of software is to change. A simple Networking class might evolve to provide an optional caching mechanism. Although it would be wrong to update the abstractions because of this change in implementation, it is definitely not wrong to update your class’s name to NetworkingCached or CachedNetworking.

Lastly, it is your responsibility as a developer to keep an eye out and update the class or variable names to keep them accurate at all times.


And that’s it. Let me know if you enjoyed reading & if any of these techniques help you or your team overcome some of the naming challenges. If you have any ideas or techniques you use, share them in the comments and I would be happy to discuss.

Good luck naming!

Written by