
Coding rules
-
code in C++ - if there are standard C++ mechanisms that implement something (a list, a container, a buffer, a string etc.) then they MUST be used unless some other interfaced code requires other techniques. After all it's a C++ project
-
major changes that may break the functionality of ParaGUI and the applications must be discussed on the devel list and _planned_ before comitting them. The author of such changes should take every care to implement the changes so that after commit the library is functional in all its basic functionality.
-
If some changes require long-term development _and_ they break the functionality of the library, the developer should request for a developement branch of the current tree.
Coding style
Grab astyle, a code formatter for C, C++, and Java, from astyle.sourceforge.net. All code in the repository should be run through astyle before being committed, with these options:
astyle --style=kr --indent=tab=4 --indent-switches filename
Doing this has several advantages:
-
Code in the repository will be consistently formatted.
-
You don't have to worry about the coding conventions while coding, or at all for that matter.
-
You can reformat code to your own personal style preference while working on it, and then easily convert it back to the way it was, along with your added code. Since astyle will format it in the exact same way, patches won't be filled with many lines of useless formatting changes.
-
It's easy.
Note: don't make a habit of formatting all source files ('just to be sure') instead of just the ones you modified. This will update the timestamps on the files and cause all hell to break loose.
Here's an outline of the code format, for the sake of completeness.. but use astyle. Please.
Sample code:
void foo(int bar) {
if (bar < 7) {
cout << bar << endl;
}
else {
cout << "That's a big bar you got there.";
}
}
Things to notice:
-
C++ style comments are best for few-line comments
-
Use C comments for commenting large blocks
-
K&R style braces, with one space before the first brace
-
No spaces padding the inside of parenthesis
-
One space padding of operators on both sides
-
An if statement's block will always be enclosed in braces, even if it is just one line.
-
Hard tabs for indents
-
And the most important thing of all, no matter what you do: Do not assume anything about the length of a tab. This means don't mix tabs and spaces in an interchangeable way. This way, everything that looks nice in an editor with 8-space tabs, will look just fine in an editor with 4-space tabs, etc.
The ParaGUI Project - Alexander Pipelka