< previous page page_62 next page >

Page 62
const float MAX_HOURS = 40.0;    // Maximum normal work hours
const float OVERTIME = 1.5;      // Overtime pay rate factor
MATTERS OF STYLE
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:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
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.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
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.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
CalcPay(payRate, hours, wages)     Cube(27)    MyDataType
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
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.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
UPPER_LIMIT   PI  MAX_LENGTH

(text box continues on next page)

 
< previous page page_62 next page >