Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Naming Matters

DZone's Guide to

Naming Matters

Keeping your code clean and understandable should always be a concern as a developer. Here are a few guidelines that can help make your code cleaner.

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

Everything around us has a name. I mean everything — otherwise, how would we be able to refer to them, particularly in programming? From our project name, directories, variables, and more, a name must be associated with every item, or else we lose their meaning and use.

So when you decide to work on a project, make sure you keep telling yourself that naming matters. There is more to a program than a compiler understanding what you’ve written and running the code. To create software, writing the code is one thing, maintaining the code is another. Sometimes, maintaining existing code is more difficult than creating a new one. We are afraid we may bring the project down. So, below are some tips I gathered from the book “Clean Code” about how to use good namings when writing programs.

  1. Make sure you use names that show your intentions. Names should explain what they do, why they do what they do, and how they do it.
  2. Endeavor to use names that carry single meaning. Do not use names that might carry very similar meanings to another thing.
  3. When there are differences between names, please make sure the distinction is clear.
  4. Ensure that names you use are easy to pronounce. Beyond communicating with the compiler, you want to be able to communicate with other developers about your project. So, use names that are easy to pronounce and reference.
  5. Use domain-specific namings properly. Use names that easily map to the domain in which you are working, and which also explains exactly how the naming works in that domain.
  6. Do not repeat namings. Ensure that not every variable you create is annotated with a certain prefix such that every name in your program has that name. This could lead to poor searching on your code.
  7. Endeavor to reach out more to the language you are using. Learn the vocabulary of the English language to help communicate more. The more words you know, the easier it is for you to communicate with other programmers.

Note: The tips given here are to guide you and are in no way rules written in stone. As more and more programmers become better aware of using good names, the world of programming would become easier not only to current programmers, but also to other programmers that will join the field later.

Imagine a scenario where you look at a variable name and no idea comes to your mind about why it even exists. You look lost in a sea of code without any idea where to move. But the worse part is you wrote the code yourself and there is no one around to explain exactly what your intentions were when you created that variable or that class.

It’s never too late to start. Start small. Do not run off changing every piece of code you have ever written just yet. You might be overwhelmed. Take it one step at a time.

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:
clean code ,java ,naming ,readability

Published at DZone with permission of Abdul Azeez Idris, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}