Other than the rules for creating identifiers, C imposes no restriction on what names to use, or what format (uppercase or lowercase, for instance) to use. However, good programming practice dictates that some common-sense rules should be followed.
An identifier should be meaningful. For example, if it’s a variable, it should reflect the value being stored in the variable; netPay is a much better variable than x for storing someone’s net pay, even though both are valid. If it’s a function, it should give some indication of what the method is supposed to do; playGame is a better identifier than plg.
It is a good idea to use upper and lower case combinations to indicate the kind of item named by the identifier. In this series, we use the following conventions:
• A variable is normally written in lowercase, for example, sum. If we need a variable consisting of two or more words, we start the second and subsequent words with an uppercase letter, for example, voteCount or sumOfSeries.
• A symbolic (or named) constant is an identifier which can be used in place of a constant such as 100. Suppose 100 represents the maximum number of items we wish to process in some program. We would probably need to use the number 100 in various places in the program. But suppose we change our mind and want to cater for 500 items. We would have to change all occurrences of 100 to 500. However, we would have to make sure that we do not change an occurrence of 100 used for some purpose other than the maximum number of items (in a calculation like principal*rate/100, say).
To make it easy to change our mind, we can set the identifier MaxItems to 100 and use MaxItems whenever we need to refer to the maximum number of items. If we change our mind, we would just need to set MaxItems to the new value. We will begin a symbolic constant with an uppercase letter. If it consists of more than one word, we will begin each word with uppercase, as in MaxThrowsPerTurn.