|
|
|
|
|
|
Capitalization of Identifiers |
|
|
|
|
|
|
|
|
|
Programmers often use capitalization as a quick, visual clue to what an identifier represents. Different programmers adopt different conventions for using uppercase letters and lowercase letters. Some people use only lowercase letters, separating the English words in an identifier with the underscore character: |
|
|
|
|
 |
|
|
|
|
pay_rate emp_num pay_file |
|
|
|
|
|
|
|
|
|
The convention we use in this book is the following: |
|
|
|
|
|
|
|
|
|
For identifiers representing variables, we begin with a lowercase letter and capitalize each successive English word. |
|
|
|
|
 |
|
|
|
|
lengthInYards sumOfSquares hours |
|
|
|
|
|
|
|
|
|
Names of programmer-written functions and programmer-defined data types (which we discuss later in the book) are capitalized the same as variable names except that they begin with capital letters. |
|
|
|
|
 |
|
|
|
|
CalcPay(payRate, hours, wages) Cube(27) MyDataType |
|
|
|
|
 |
|
|
|
|
Capitalizing the first letter allows a person reading the program to tell at a glance that an identifier represents a function name or data type rather than a variable. However, we cannot use this capitalization convention everywhere. C++ expects every program to have a function named mainall in lowercase lettersso we cannot name it Main. Nor can we use Int for the built-in data type int. C++ reserved words use all lowercase letters. |
|
|
|
|
|
|
|
|
|
For identifiers representing named constants, we capitalize every letter and use underscores to separate the English words. |
|
|
|
|
 |
|
|
|
|
UPPER_LIMIT PI MAX_LENGTH |
|
|
|
|