
Some of the reasons for using a style guide are:
The explicit rules listed on this page are designed to help you avoid some obvious code style violations. You should also look at the existing code and make your code as consistent as possible.
Style guide complicance is, however, not nearly as important as high quality code. If your code uses high quality coding standards, your instructor will be much more lenient on any small differences in code style.
Indent to show structure. Use 3 spaces to indent. Do not use tab characters.
Where possible, configure editors to insert spaces instead of tab characters - the tab character is interpreted differently by different programs and its use in the formatting of code should be avoided.
LIKE_THIS and don't use common
words or abbreviations.LikeThis.likeThis..c. C++
implementation files should be given the extension .cpp. A
C++ source file should be named after the principal class it contains.
Example: The C++ class SomeClass would have header file
SomeClass.h and body file SomeClass.cxx.
void useBracesLikeThis(int x)
{
// Always add braces, even if it's only a single statement.
if (x < 3)
{
cerr << "well done" << endl;
}
}
Be a C++ programmer as much as possible, for example:
#define when you could use
const;
// Even better, use iterators
for (int i = 0; i < v.size(); i++)
{
// do stuff
}
_MSC_VER for interfacing to the Win32 API.
HUGE_VAL.
Last edited Mon Jun 4 21:14:14 2007 by John Funge.