Importance of Naming in Programming

Bilhasry Ramadhony
3 min readSep 22, 2021
Photo by Pakata Goh on Unsplash

Naming is the way for us to identify a certain object. We name an object that enable us to communicate with other people from a distance is a “telephone”. By giving name to an object made us easy to remember about that object, instead of explaining what the object looks like and what does it do.

The same thing apply in programming. The code that we write today, is not only us who will maintain that code. But there will be a next developer that will work on the code and maintain it.

Function, variables, class, constants and other element in our code should be something that easily understand by the next developer.

Benefits of Having Good Naming

Base on my experience during my working by reviewing other people code and reading some of articles, these are the benefits that we can get from a good naming in programming

Prevent Context Switching

As developer, we read more code than writing it. Reading code and reading comment that exist in the code is two different context.

Reading code is in the context we want to understand how is the logic happened in a piece of code.

Meanwhile reading the comments in the code is to understand what is the message that the author of the code try to explain.

/**
* this function is to update user status
* @input id for user id
* @input status for new status
**/
function update($id, $status)
{
// your code will be here
}

Sometimes, we found a function with the long comment to explain about the function itself. If each of the function needs that long explanation, most of our code might be full of comment to just explain what is the function or a variable about.

We can make above code to be easy to read by changing it to this below:

function updateUserStatus($userId, $newStatus)
{
// put your code here
}

Make Things Consistent

Being consistent make your code easy to manage and maintain. On the other hand, it will help the developer to follow the current naming convention that the company has.

If we have consistent naming it is much easier for the developer to write the code itself, for example there are function naming like this

function fetchData();
function getData();
function retrieveData();

Three of them has the same meaning about retrieving data from any resources. Which name that we choose of that three functions, for example we choose retrieve, we must stick with that for another kind of data retrieval.

Make Things Easier to Understand

const fName; //first Namefunction KillThemAll(); // I don't know what is this function about

Sometimes we found, some piece of code that writing like above. It makes us as developer hard to understand what is the meaning behind that function or constant.

By having good naming convention, it makes thing easier to understand for the next developer. They don’t need to ask to any colleague or read the entire logic to understand what is that function or variable about.

Some of good naming that is easier to understand

const isEnabled;function insertElement();

Final Thoughts

As developer, what we code today is the legacy for the next developer. Be aware about choosing the right naming for your variables, functions, class or any other objects on your code.

It is always a headache if we deal with a code that doesn’t properly naming, and it takes us a lot of time to fully understand about the code itself.

Happy Coding!

Some Additional Resource to Read

--

--