2002-12-03 12:46:32 +00:00
|
|
|
|
Use 4 space indent
|
2002-07-23 16:10:49 +00:00
|
|
|
|
Spaces between ","
|
2002-12-03 12:46:32 +00:00
|
|
|
|
ex: 1, 2, a, 4
|
2002-07-23 16:10:49 +00:00
|
|
|
|
|
|
|
|
|
if/else-statements:
|
|
|
|
|
An else clause is joined to any preceding close curly brace
|
|
|
|
|
that is part of its if.
|
|
|
|
|
|
|
|
|
|
if (....) {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
....
|
2002-07-23 16:10:49 +00:00
|
|
|
|
} else {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
....
|
2002-07-23 16:10:49 +00:00
|
|
|
|
}
|
|
|
|
|
if the line needs to be splited up, right after an if-statement
|
2001-12-11 20:47:02 +00:00
|
|
|
|
use {<7B>and }, so its clear when the if-statement ends.
|
2002-07-23 16:10:49 +00:00
|
|
|
|
ex:
|
|
|
|
|
if (...) {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
function(.....,
|
|
|
|
|
......, .... );
|
2002-07-23 16:10:49 +00:00
|
|
|
|
}
|
2001-12-11 20:47:02 +00:00
|
|
|
|
|
2002-07-23 16:10:49 +00:00
|
|
|
|
This is ok:
|
|
|
|
|
if (...)
|
2002-12-03 12:46:32 +00:00
|
|
|
|
shortline(...);
|
2002-07-23 16:10:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while-statement:
|
|
|
|
|
|
|
|
|
|
while (...) {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
....
|
2002-07-23 16:10:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for-statement:
|
|
|
|
|
|
|
|
|
|
for (init; condition; update) {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
....
|
2002-07-23 16:10:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (longinit;
|
2002-12-03 12:46:32 +00:00
|
|
|
|
longcondition;
|
|
|
|
|
longupdate ) {
|
|
|
|
|
....
|
2002-07-23 16:10:49 +00:00
|
|
|
|
}
|
|
|
|
|
alt form:
|
|
|
|
|
|
|
|
|
|
init;
|
|
|
|
|
for (; condition; update) {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
....
|
2002-07-23 16:10:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do-statement:
|
|
|
|
|
|
|
|
|
|
do {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
....
|
2002-07-23 16:10:49 +00:00
|
|
|
|
} while (...);
|
|
|
|
|
|
|
|
|
|
switch-statement:
|
|
|
|
|
should always have a default value.
|
|
|
|
|
Enum values is an exception, they should not have a default: , when you add
|
|
|
|
|
new values to an enum you might forget to add them to switch statement.
|
|
|
|
|
|
|
|
|
|
switch (...) {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
case ...:
|
|
|
|
|
...;
|
|
|
|
|
break;
|
|
|
|
|
case ...: {
|
|
|
|
|
...;
|
|
|
|
|
} break;
|
|
|
|
|
case ...:
|
|
|
|
|
...;
|
|
|
|
|
default:
|
|
|
|
|
....;
|
|
|
|
|
break;
|
2002-07-23 16:10:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Include guards:
|
|
|
|
|
For files with namespace:
|
|
|
|
|
#ifndef NAMESPACE_FILENAME_HH
|
|
|
|
|
#define NAMESPACE_FILENAME_HH
|
|
|
|
|
....
|
|
|
|
|
|
|
|
|
|
#endif //NAMESPACE_FILENAME_HH
|
|
|
|
|
<eof>
|
|
|
|
|
|
|
|
|
|
Without namespace:
|
|
|
|
|
#ifndef FILENAME_HH
|
|
|
|
|
#define FILENAME_HH
|
|
|
|
|
....
|
|
|
|
|
|
|
|
|
|
#endif //FILENAME_HH
|
|
|
|
|
|
|
|
|
|
<eof>
|
2002-01-18 01:38:44 +00:00
|
|
|
|
|
2002-07-23 16:10:49 +00:00
|
|
|
|
preprocessors:
|
|
|
|
|
The # of all preprocessor commands must always be in column 1, and never use
|
|
|
|
|
indentation for preprocessor directives
|
2002-01-06 11:51:53 +00:00
|
|
|
|
|
2002-07-23 16:10:49 +00:00
|
|
|
|
They should always have a // PREPROCESSOR to mark where they end
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
...
|
|
|
|
|
...
|
|
|
|
|
#endif //DEBUG
|
2001-12-11 20:47:02 +00:00
|
|
|
|
|
2002-07-23 16:10:49 +00:00
|
|
|
|
Don't use preprocessors for constants or macro-functions, they can be
|
|
|
|
|
cryptic and sometime make it hard to debug.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
functions:
|
|
|
|
|
The name starts with a lowercase and then a uppercase for name separation:
|
|
|
|
|
void functionWithAName(...) {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
...;
|
2002-07-23 16:10:49 +00:00
|
|
|
|
}
|
2001-12-11 20:47:02 +00:00
|
|
|
|
|
2002-12-03 12:46:32 +00:00
|
|
|
|
Use Javadoc style for function description (see www.doxygen.org)
|
2001-12-11 20:47:02 +00:00
|
|
|
|
Function comments:
|
2002-12-03 12:46:32 +00:00
|
|
|
|
/**
|
|
|
|
|
This do that and that
|
|
|
|
|
@return this on success else this on failure.
|
|
|
|
|
TODO: if there is something to do.
|
|
|
|
|
*/
|
2002-07-23 16:10:49 +00:00
|
|
|
|
void functionDoes(...) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Class:
|
|
|
|
|
Order: public, protected and then private
|
|
|
|
|
Class names always starts with a big letter.
|
|
|
|
|
Class data members are prefixed by m_ , static data members are prefixed with s_ .
|
|
|
|
|
Class member function will be organized according to creator,
|
|
|
|
|
manipulator and accessors categories.
|
|
|
|
|
|
|
|
|
|
class Classname:public AnotherClass {
|
|
|
|
|
public:
|
2002-12-03 12:46:32 +00:00
|
|
|
|
//1. public enums, structs
|
|
|
|
|
|
|
|
|
|
//2. constructors and destructor
|
|
|
|
|
|
|
|
|
|
//3. manipulators
|
|
|
|
|
|
|
|
|
|
//4. accessors
|
|
|
|
|
|
2002-07-23 16:10:49 +00:00
|
|
|
|
protected:
|
2002-12-03 12:46:32 +00:00
|
|
|
|
//1. enums, structs
|
|
|
|
|
|
|
|
|
|
//2. functions
|
|
|
|
|
|
|
|
|
|
//3. variables
|
2002-07-23 16:10:49 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2002-12-03 12:46:32 +00:00
|
|
|
|
//1. enums, structs
|
|
|
|
|
|
|
|
|
|
//2. functions
|
|
|
|
|
|
|
|
|
|
//3. variables
|
2002-07-23 16:10:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct follows the class style.
|
|
|
|
|
|
|
|
|
|
namespace:
|
|
|
|
|
namespace TheName {
|
|
|
|
|
...;
|
|
|
|
|
...;
|
|
|
|
|
}; //end namespace TheName
|
|
|
|
|
|
|
|
|
|
Don't use "using namespace thenamespace;" in header-file
|
|
|
|
|
We don't want to force the other files, that include the file, a namespace.
|
|
|
|
|
|
2001-12-11 20:47:02 +00:00
|
|
|
|
|
2002-07-23 16:10:49 +00:00
|
|
|
|
try/catch-statement:
|
|
|
|
|
|
|
|
|
|
try {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
....;
|
2002-07-23 16:10:49 +00:00
|
|
|
|
} catch (...) {
|
2002-12-03 12:46:32 +00:00
|
|
|
|
....;
|
2001-12-11 20:47:02 +00:00
|
|
|
|
}
|
2002-01-06 11:51:53 +00:00
|
|
|
|
|
2002-07-23 16:10:49 +00:00
|
|
|
|
Variables:
|
|
|
|
|
Avoid variables that contain mixtures of the numbers 0 & l and the letters O
|
|
|
|
|
and 1, because they are hard to tell apart.
|
|
|
|
|
Having a type name and a variable differing in only in case (such as:
|
|
|
|
|
String string;) is permitted, but discouraged.
|
|
|
|
|
|
|
|
|
|
Use lowercase for variables and use _ to separate names, ex:
|
|
|
|
|
int number_of_screens;
|
|
|
|
|
int num_colors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
All constants must be in Upper case letters.
|
2002-01-06 11:51:53 +00:00
|
|
|
|
|
2002-01-18 01:38:44 +00:00
|
|
|
|
enums must be in uppercase letters and not in file scope:
|
2002-01-06 11:51:53 +00:00
|
|
|
|
enum {WHITE, RED, BLUE};
|
|
|
|
|
|
2002-07-23 16:10:49 +00:00
|
|
|
|
Other:
|
|
|
|
|
|
|
|
|
|
if (strcmp(...) == 0) //good
|
|
|
|
|
if (!strcmp()) //bad
|
|
|
|
|
|
|
|
|
|
Don't create free-functions, encapsulate them in a namespace or a class
|
|
|
|
|
and name filenames so it's clear what they hold so it's easier to find
|
|
|
|
|
functions, classes and other stuff.
|
|
|
|
|
|
2002-09-07 18:56:49 +00:00
|
|
|
|
|
|
|
|
|
ChangeLog format:
|
|
|
|
|
*year/month/day:
|
|
|
|
|
* whats changed (who changed it)
|
|
|
|
|
which file
|
|
|
|
|
|
|
|
|
|
ex:
|
|
|
|
|
|
|
|
|
|
*02/01/01:
|
|
|
|
|
* Fixed bug workspace change (TheDude)
|
|
|
|
|
Workspace.cc
|
|
|
|
|
|