Using meaningful names

Wherever possible, meaningful names should be used for variables, procedures and functions. Look at this simple Python program:

x = int(input("Enter x: ")) y = x * 4 print("y = ") print(y)

At first glance it may be hard to understand what this program does. It is clear that one number is inputted and another number is outputted, but beyond that it is not clear what the purpose of the program is.

Now look at this simple Python program:

length = int(input("Enter the length of one side: ")) perimeter = length * 4 print("Perimeter of your square is: ") print(perimeter)

This time it is much easier to determine the purpose of the program (ie to calculate the perimeter of a square). The only difference between the two programs is that the second program uses meaningful names for variables (and in messages).

A meaningful name is one that allows us to easily understand what the variable, procedure or function does or is used for.

Meaningless names make code hard to understand. Sensible and meaningful names make the purpose of code easy to decipher.