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.

--

--

--

I’m a front-end web developer that loves to chug coffee. I love to work on accessible products with people that champion the same ideas that I hold.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Occupational Profiles in the EO/GI Domain — A Trend Analysis from the EO4GEO Project

how to download youtube video as video using python

Open Source SEO: PHP and HTML Coding Style We Want for Miami SEO

Deploy Kafka Cluster in Dev. Environment with docker-compose

Debugging our Cloud Function in Real Time

Optional In JAVA8

Documentation

Chapter 14 -Serialization and File I/O: Saving Objects

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Josh Chu

Josh Chu

I’m a front-end web developer that loves to chug coffee. I love to work on accessible products with people that champion the same ideas that I hold.

More from Medium

Top 3 Casts of the Week #3

Should you hire developers, outsource or find a consulting/development firm?

How I Lost Auto Formatting In WebStorm!

The start of my largest software engineering project (Use cases, thesis, technologies and…