• Home
• /
• Blog
• /
• Naming Conventions in Programming Explained to Kids

# Naming Conventions in Programming Explained to Kids

October 22, 2020

This post is also available in: हिन्दी (Hindi)

Do you know what is Camel Case, Snake Case, or Kebab Case? What do all these terms refer to? These all are the types of Naming Conventions in Programming.

In general, code is written once but read multiple times, by others in the project team or even those from other teams. Readability is therefore important. Readability is nothing more than figuring out what the code does in less time.

Among the many best coding practices, variables, functions, classes, and even files are named in a project. This is called the Naming Convention.

## What is Camel Case? What is a Naming Convention?

A naming convention is a set of rules applied when creating text scripts for software programming. It is used to name different program parameters such as identifiers that denote variables, types, functions, and other entities in source code and documentation.

They have many different purposes, such as adding clarity and uniformity to scripts, readability for third-party applications, and functionality in certain languages and applications. They range from capitalization and punctuation to adding symbols and identifiers to signify certain functions.

## Rules for Naming Convention

Following are the basic rules that one should follow while naming the identifiers in their code:

### 1. Consistency

This rule says that “Pick one word per concept – use the same concept across the code”.

fetchFirstName() {...}
getFirstName() {...}
retrieveFirstName() {...}


All the three names of the above methods are the same and can be interpreted as the same operation. It doesn’t matter which one we actually pick, but it’s important that we’re consistent throughout the code. If we decide that fetch will request data remotely, we should stick with that convention for fetchFirstName, fetchLastName, and fetchCustomerAddress for instance.

### 2. Meaningful

Consider the following names:

const users;
const numberOfUsers;
const friends;
const friendsOfCurrentUser;


Clearly, you can see that const users and const friends are confusing whereas const numberOfUsers and const friendsOfCurrentUser are successful in conveying the meaning.

We write code with a 100% mindset of that feature or context. But we forget that the next reader might come with a different mindset, so we should make sure we avoid ambiguity.

### 3. Meaningful Distinctions

It refers to the use of meaningful words under different circumstances. Let’s consider the following example to understand this.

// Function in Class A
return x + y;
}
// Function in Class B
}


In class A, the add(x, y) function is adding 2 numbers and in class B add(x) is inserting an element to a collection. Both function names are correct, but without deep-dive to their implementations, you won’t be able to understand and use them.

A better name will be:

### 4. Use Pronounceable Names

Consider these names

const lblFrtName; // First name label
const nowTsMs; // now date timestamp since 1980 in milliseconds


These kinds of variable names are hard to pronounce and no one will be able to remember them. Moreover, our code should be able to be searchable. When the program becomes bigger and bigger we search more. Better naming makes scaling easier.

### 5. Don’t be Offensive

Consider these names:

function killThemAll();
function whack();
function giveSomeLove();


Remember, we are living in the age of the Internet. Many of the projects you work on are online. The name you pick for your function will be read by a variety of people. The same thing can be interpreted differently by different people.

Naming convention should be generic, and as professional as possible, and should not include any cultural slang.

### 6. Be Positive

Consider the following names:

As humans, we have a better understanding of the positive approach, so we should use them in the names we pick.

isDisabled should become isEnabled

isUndefined should become isDefined

shouldNotShowScreen should become shouldShowScreen

## What is Camel Case?

The names of parameters in a program are styled differently by different people, but some of the most common styles in practice are:

### 1. Camel Case

The first letter of every word is capitalized with no spaces or symbols between words. For example FirstName, ContactNumber, LastName

### 2. Pascal Case

It was popularized by Pascal programming language and it is a subset of Camel Case where the word starts with uppercase. Thus, FirstName is in Pascal Case but not firstName.

### 3. Snake Case

Words within phrases or compound words are separated with an underscore. For example first_name, contact_number, last_name.

### 4. Kebab Case

It is similar to Snake Case, but hyphens are used in place of an underscore. For example first-name, contact-number, last-name.

### 5. Screaming Case

Words consist of all capital letters. For example FIRSTNAME, CONTACTNUMBER, LASTNAME.

### 6. Hungarian Notation

Names start with a lowercase prefix to indicate intention. Rest of the name is in Pascal Case. It comes in two variants:

• Systems Hungarian, where prefix indicates the data type. For example intFirstNumber, strFirstName, arrUserNames
• Apps Hungarian, where prefix indicates logical purpose. For example rowPosition, colPosition, pchName