Main Page Class Hierarchy Compound List File List Compound Members File Members Related Pages Examples

## Coding conventions for ParaGUI

## The Easy Route

Grab astyle, a code formatter for C, C++, and Java, from http://astyle.sourceforge.net. All code in the repository should be run through astyle before being committed, with these options:

    astyle --style=kr --indent=tab <filename>

Or, to make life easy, you can put this file in ~/.astylerc and just run:

    astyle <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:

    // No, this code is not supposed to make sense
    void foo(int bar) {
    	if (bar < 7) {
    		cout << bar << endl;
    	}
    	else {
    		cout << "That's a big bar you got there.\n"
    	}
    }

## 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.