[ fromfile: style.xml id: style ]
In any serious collaborative programming project there are likely to be style guidelines to improve the readability, reusability, maintainability, and reliability of the code produced.
Here is a summary of the style guidelines that we have adopted.
Names are sequences of letters and numerical digits, the first of which must not be a digit.
The underscore character ('_') can be used also but we discourage the use of that character except for class data members.
Class names begin with a capital letter: class Customer
Function names begin with a lowercase letter.
Use CamelCase to form multi-word names by joining the words together and capitalizing the interior word beginnings; e.g., class MetaDataLoader
, void getStudentInfo()
Constants are capitalized and created, preferably, as enum
values in a class scope. Global constants and macros are usually all CAPS
.
Each class name should be a noun or a noun phrase: class LargeFurryMammal
for example.
Each function name should be a verb or a verb phrase: processBookOrder()
for example.
Each bool
variable name should produce a reasonable approximation of a sentence when used in an if()
statement: bool isQualified
for example.
data members: m_Color, m_Width
- prepend lowercase m_
static
data members: s_Singleton, s_ObjCount
- prepend lowercase s_
For each attribute, we have naming conventions for their corresponding getters/setters.
Non-boolean getters: color()
or getColor()
[22]
Boolean getters: isChecked()
or isValid()
setter: setColor(const Color& newColor)
A consistent naming convention greatly improves the readability and maintainability of a program.
[22] The latter is Java style, the former is Qt style. Both conventions are widely used. Try to follow one convention consistently in your code. (We are not consistent in this book because we want to expose the reader to different conventions.)
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |