fluxbox/doc/Coding_style

225 lines
3.7 KiB
Text
Raw Normal View History

2002-07-23 16:10:49 +00:00
Use hard tab for indentation. (size 4)
Spaces between ","
ex: 1, 2, 3, 4
if/else-statements:
An else clause is joined to any preceding close curly brace
that is part of its if.
if (....) {
....
} else {
....
}
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 (...) {
function(.....,
......, .... );
}
2001-12-11 20:47:02 +00:00
2002-07-23 16:10:49 +00:00
This is ok:
if (...)
shortline(...);
while-statement:
while (...) {
....
}
for-statement:
for (init; condition; update) {
....
}
for (longinit;
longcondition;
longupdate ) {
....
}
alt form:
init;
for (; condition; update) {
....
}
do-statement:
do {
....
} 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 (...) {
case ...:
...;
break;
case ...: {
...;
} break;
case ...:
...;
default:
....;
break;
}
goto-statement:
DONT USE IT!
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(...) {
...;
}
2001-12-11 20:47:02 +00:00
Function comments:
// This do that and that
// Returns this on success else
// this on failure.
// TODO: if there is something to do.
2002-07-23 16:10:49 +00:00
void functionDoes(...) {
}
Comments:
Use // on few line comments.
Use
/*
...
...
*/
when there are a lot to comment
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:
//1. public enums, structs
//2. constructors and destructor
//3. manipulators
//4. accessors
protected:
//1. enums, structs
//2. functions
//3. variables
private:
//1. enums, structs
//2. functions
//3. variables
};
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 {
....;
} catch (...) {
....;
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