10 Simple Rules for Creating Meaningful Names

Sheetal Jain
3 min readApr 21, 2023

Summer internships and joining dates are just around the corner, and the proof of your knowledge will now be found in just one place: the code. Now you are a programmer but if you want to be a better programmer you are not only supposed to write code, clean code is required.

For a new programmer, it may come as a surprise that your bad code can actually bring the company down and you have probably been significantly slowed down by someone else’s messy code. So keeping your code clean is not just cost-effective; it’s a matter of professional survival.

Names are everywhere in software. We name our variables, functions, classes and packages. We name our jar files and war files and ear files. We name and name and name. Because we do so much of it, we’d better do it well.

Ten simple rules for creating good names:

  1. Use Intention-Revealing Names: The name of a variable function or class should answer all the big questions. It should tell you why it exists, what it does and how it is used. if a name requires a comment then the name doesn’t reveal its intent.
  2. Avoid Disinformation: We should avoid words whose entrenched meanings vary from our intended meaning. For e.g. hp, aix etc. Do not refer to a grouping of accounts as an accountList unless it's actually a List.
  3. Make meaningful Distinctions: Noise words are another meaningless distinction. Imagine that you have a Product class. If you have another called ProductInfo or ProductData. Info and Data are indistinct noise words like a, an and the. Distinguish names in such a way that the reader knows what the differences offer.
  4. Use Searchable Names: Single-letter names and numeric constants have a particular problem in that they are not easy to locate across a body of text. The length of a name should correspond to the size of its scope.
  5. Avoid Mental Mapping: Readers shouldn’t have to mentally translate your names into other names they already know. This problem generally arises when you don’t use either problem domain names or solution domain names.
  6. Class Names: Classes and objects should have noun or noun phrase names like Customer, WikiPage, and Account. A class name should not be a verb.
  7. Method Names: Methods should have verb or verb phrase names like postPayment, deletePage etc.
  8. Don’t be cute: If names are too clever, they will be memorable only to people who share the author’s sense of humour. Choose clarity over entertainment value.
  9. Pick one word per concept: Pick one word for one abstract concept and stick with it. For e.g, it’s confusing to have fetch, retrieve and get as equivalent methods of different classes.
  10. Use Solution and Problem Domain Names: Remember that the people who read your code will be the programmers. So go ahead and use CS terms, algorithm names, pattern names, math terms and so forth. When there is no “programmer-eese” for what you are doing, use the name from the problem domain.

Thank you and stay tuned! I’ll write more about clean code soon.

--

--