In order to make our programs more readable, we are allowed to create our own meaningful names for values used in our program. These are known as user-defined symbols (or identifiers) and are used to create named constants, variables and functions. We are allowed to use the alphabetic characters, digits and the underscore character (_) when creating user-defined symbols. User-defined symbols can not start with a digit to avoid confusion with numeric literals.
Symbols are case sensitive meaning that uppercase and lowercase alphabetic characters are considered different characters. For example, the symbols
taxRate are three separate and distinct symbols.
Because we can use upper and lower case when defining symbols, we often adopt a convention so that it is easy to remember what case is used for our symbols. Common conventions are Camel Case, Pascal Case, All Caps, and Underscore (Unix) case. These styles differ in how long, multi-word symbols are constructed.
When constructing multi-word symbols using the Camel Case convention we run all the words together and nominally use lower case characters. The exception is to use an uppercase character for the first letter in each word starting with the second word. This style became popular in languages such as Java and when writing programs with a GUI. It is often used for variable and function names. Examples of Camel Case symbols are:
This is very similar to Camel Case. The only difference is that with Pascal Case, the first word and all subsequent words are capitalized. This style became popularized by the Pascal programming language and is often used when naming user-defined data types. Examples of Pascal Case symbols are:
The Underscore Case is often used in Unix programming. It uses only lower case characters and uses the underscore to separate words in multi-word symbols. For example.
The All Caps style only uses capital letters. It may or may not use the underscore to separate words in multi-word symbols, however using the underscore makes such symbols easier to read. This style is typically used for named constants and not used for variables. For example:
- Which of the following are valid identifiers?
- Even though most any Unicode character can be used in an indentifier, what are some reasons for limiting identifiers to ASCII alphanumerics?