Skip to main content

Section 2.9 ๐Ÿ‘ฉโ€๐Ÿ’ป Choosing the Right Variable Name

Programmers generally choose names for their variables that are meaningful to the human readers of the program โ€” they help the programmer document, or remember, what the variable is used for. Beginning programmers sometimes think it is funny to use strange or obscene names for their variables. This is not good practice and will not amuse your professor. Get in the habit of using meaningful names right away.

Warning 2.9.1.

Beginners sometimes confuse โ€œmeaningful to the human readersโ€ with โ€œmeaningful to the computerโ€. So theyโ€™ll wrongly think that because theyโ€™ve called some variable average or pi, it will somehow automagically calculate an average, or automagically associate the variable pi with the value 3.14159. No! The computer doesnโ€™t attach semantic meaning to your variable names.
So youโ€™ll find some instructors who deliberately donโ€™t choose meaningful names when they teach beginners โ€” not because they donโ€™t think it is a good habit, but because theyโ€™re trying to reinforce the message that you, the programmer, have to write some program code to calculate the average, or you must write an assignment statement to give a variable the value you want it to have.
You have attempted 1 of 1 activities on this page.