Next: TABs and spaces
Up: C++
Previous: Comments
- Names representing types must be in mixed case, starting with upper
case.
- Example:
-
-
- Line, SavingsAccount
- Reason:
- Common practice in the C++ development community.
- Variable names must be in mixed case starting with lower case.
- Example:
-
-
- line, savingsAccount
- Reason:
- Common practice in the C++ development community.
- Named constants (including enumeration values) must be all uppercase
using underscore to separate words.
- Example:
-
-
- MAX_ITERATIONS, COLOR_RED, PI
- Reason:
- Common practice in the C++ development community
- Names representing methods or functions must be verbs and written
in mixed case starting with lower case.
- Example:
-
-
- getName(), computeTotalWidth()
- Reason:
- Common practice in the C++ development community.
- Names representing namespaces should be all lowercase.
- Example:
-
-
- analyzer, iomanager, mainwindow
- Reason:
- Common practice in the C++ development community.
- Names representing template types should be a single uppercase letter.
- Example:
-
-
- template<class T> ... template<class C, class D> ...
- Reason:
- Common practice in the C++ development community.
- All names should be written in english.
- Example:
-
-
- fileName; // NOT: filNavn
- Reason:
- English is the prefered language for international development.
- Abbreviations and acronyms must not be uppercase when used as name
- Example:
-
-
- exportHtmlSource(); // NOT: exportHTMLSource();
- Reason:
- When the name is connected to another, the readbility is
seriously reduced; the word following the abbreviation does not stand
out as it should.
- Global variables should always be referred to using the :: operator.
- Example:
-
-
- ::mainWindow.open(), ::applicationContext.getName()
- Reason:
- For doing global variables separated from other.
- Private class variables should have underscore suffix.
- Example:
-
-
- class SomeClass {
private:
int length_;
public:
};
- Reason:
- This is important because class variables are considered
to have higher significance than method variables, and should be treated
with special care by the programmer.
- Variables with a large scope should have long names, variables with
a small scope can have short names
- Example:
-
-
- i, j, k, ::objectForAllProject;
- Reason:
- Scratch variables used for temporary storage or indices
are best kept short
- The name of the object is implicit, and should be avoided in a method
name.
- Example:
-
-
- line.getLength(); // NOT: line.getLineLength();
- Reason:
- The latter seems natural in the class declaration, but proves
superfluous in use, as shown in the example.
Next: TABs and spaces
Up: C++
Previous: Comments
2005-07-21