Identifiers

An identifier is basically a name. It can be the name of a:

An identifier cannot be one of the keywords.

An identifier must start with one of the 53 letters (upper and lower case letter plus underscore). The second and subsequent characters of a name can be either one of the 53 letters or one of the 10 digits.

An identifier can be of any length, but only up to a fixed number of letters are used to distinguish between names. Any letters beyond this number are simply ignored. This limit is 31 characters. Some compilers give the ability to change this limit - within bounds. Thus if the length limit was set to 10, then the following two identifiers would be indistinguishable:

	temperature_high
	temperature_low

Even with the limit at 10, this problem could be eliminated by using instead the names:

	high_temperature
	low_temperature

In some implementations, the limit for external names, i.e. names used between source files, may be further restricted to only 6 or 8 characters and may make upper and lower case letters look the same. Fortunately, this is very rarely a problem any more.

An identifier must always be intact. There can be no white space (or comments) within it. Thus "high temperature" is two identifiers and tokens and not one. Similarly, an identifier must not be partly on one line and partly on another:

	high_temp
	temperature

Although it is lexically correct to have names consisting of only one or two letters, in most instances this is bad programming practice. It is far better to take the little extra time needed to use a name which is longer but meaningful. If a particular function is used to draw a straight line on the screen or a printed page then it is far better to call that function:

     draw_line()
or
     print_line()
rather than:

     f3()

Similarly for variables, it helps to document the program to use names for data objects that tell what they are, such as:

     pressure             linecount       size
     maximum_weight       average_age     frequency
     lowest_age           manuf_cost      NAME
     EngineTemperature    Voltage         phone

Tags should similarly describe the set of items that they name:

     day_of_week     book_info
     color           address
     address         date

An identifier or name belongs to one of five name spaces. This means that the same identifier can be declared, at most once, in each name space without getting an error about duplicate names.

These five name spaces are:


© 1991-2008 Prem Sobel. All Rights Reserved.