Naming in Coding

The most effective naming of variables and functions in coding.

Muhammed IŞIK

Flutter | Mobile Development

Naming is one of the most important thing in coding. Especially when we work as a team. A good named variable or function give us more information even if we don’t inspect the related codes. However a bad naming causes more confusing, coding at lower speed and failing at sustainability. This is because we should give a good name our variables and functions. No need to be quick at this stage otherwise it will influence entire project.

Here is some examples of good naming:

For example we are developing a player app that has audios. We will have state of playing that is boolean:
bool playing = true; (bad)
bool isPlay = true; (bad)
bool isPlaying = true; (good)
Because it is a continuous action it must be like that.

Another state is a state that takes place at once like pausing or stopping:
bool paused = true; (bad)
bool isPause = true; (bad)
bool isPaused = true; (good)
Because it is a sudden action it must be like that.

Integer naming also must be like this. We have many audios, we need their durations:
int audioDuration = 150; (bad)
int audioLength = 150; (bad)
int audioDurationInSeconds = 150; (good)
int audioLengthInSeconds = 150; (good)
We need to specify more to make it clear.

As a list type, naming should be like this:
List audios = […]; (bad)
List favorites = […]; (bad)
List listOfAudios = […]; (good)
List listOfFavorites = […]; (good)
We do operations over lists therefore to specify as “listOfSomething” increases speed of coding.

Finally we have functions in order to manage playing, pausing, skipping to next or previous:
void playAudio() {} (not good)
void skipNextAudio() {} (very bad) // Need to indicate direction otherwise causes misunderstanding
void skipToNextAudio() {} (not good)
void play() {} (good)
void skipToNext() {} (good)
No need to indicate we are playing audio. “play” and “skipToNext” are simple, understandable and informative.

In conclusion, even though naming depends on what will be done, general procedure should be like this.

We are the partners you’ve been searching for.

Tell us about your project.