A simple way to name Variables and Functions
Throughout my journey up until now, I have been naming my variables and functions in a way that is convenient for me. I often assume that it won’t matter since I’m just doing this to practice and besides the web apps that I’m making is not that complicated to require such strict rules. Well, I was wrong.
When the time came that I wanted to make some improvements to the projects I made, It was a nightmare trying to understand what func1() does, or what var3 means.
These are the kinds of details we often miss out because we are too deep in understanding the intricacies of a language that we overlook the small yet important principles, just like the proper naming of variables. This seems so trivial, and yes it doesn’t affect the performance of the code. However, the code you are making is not only for the computer to understand, but also for other developers, for reviewers and especially for the future you.
The more you sweat in training, the less you bleed in battle.
There is no one way to properly name variables and functions, but I think that the following is the best:
The key is to be simple and direct, Variables should be named exactly as what they represent or what they are and functions should be named according to their functionality or what they do.
Example for variables.
As you can observe it is much easier to say what the variable userName contains.
Example for functions.
Seeing the logIn() function we can easily infer that this function is used to log in users.
Yes, there are other important topics that you should be spending your time with, but understanding something is not all about the hard parts, but also the “easy part”. If we continue to name our variables and functions the way I did it, then surely it would be hard to change this habit when the time comes that we become Web developers or software engineers, etc. To do great at big and complicated projects, be your best at small side projects. Let’s always call ourselves out.
By Improving 1% at a time, we become 1% percent closer to become better.