Names

Indentation - NO TAB CHARACTERS

Indentation is by four spaces (0x20) at a time. There should be no tab characters (0x09) anywhere in Rosegarden source code. The indentation should look the same regardless of whether you read it in an IDE, in a terminal window with “cat” or “vi”, in Emacs, or quoted in an email. It must not depend on having the right settings for tab-to-space conversion in your IDE when you read it. (Emacs and vim users will note that we already start every source file with a meta-comment that sets up the right indentation mode in these editors.)

NOTE: As of revision 13,509, Rosegarden has 8,691 tab characters in 287 files. Rosegarden 10.02 had 9,598 tab characters in 262 files. The good news is fewer tabs overall, but the bad news is 25 new files have tabs that never had tabs before. New developers are ignoring this rule, apparently.

Namespaces

No extra indentation inside namespaces; set off inner code by two carriage returns on either side of namespace brackets

No whitespace between if (and other C++ keywords) and the ( makes Michael's eyes hurt.

Pointers

Pointers are MyObject *ptr; not MyObject* ptr;

Argument Alignment

If you have more arguments than will fit on a reasonable length line (80 characters is a good figure, but this is not a hard rule), align the extra arguments below and just after the opening ( rather than at a new level of indentation:

If in doubt, please err on the side of putting in too many comments. We have contributors of all ability levels working here, and what may seem obvious to you might be complete gibberish to someone else. Comments give everyone a better chance to be useful, and they are always welcome, while nobody will think you are a super code warrior or code gazelle for committing a thousand lines that have only three choice comments

When commenting out a large block of text, it is preferable to use C++ style

(The reason C++-style comments are preferred is not arbitrary. C++-style comments are much more obvious when viewing diffs on the rosegarden-bugs list, because they force the entire block of text to be displayed, instead of only the starting and ending lines.)

#include Order

Includes should try to follow the following pattern (from local to global):

Variables

You should feel encouraged to use variables to make the code easier to understand without a look at the header or the API docs. Good:

int spacing =3;
bool useHoops =false;
doSomething(spacing, useHoops);

avoid:

doSomething(3,false);

Note that you should not feel like you have to take this to ridiculous extremes. Just bear it in mind, especially when it's something obscure enough you've just had to go look at the header or the API yourself to figure out what some static parameter was for.

Sometimes variables are simple and disposable, and names like i or n are appropriate, but unless your variable is something extremely simple and obvious, like an iterator, then it is preferable to use more verbose variable names in order to give the people who follow you a year later some shred of a hint what you were thinking when you wrote the code. This particularly egregious example does some rather complicated transformations that would have been crystal clear to the author at the time, but coming at it as a stranger, it's really just short of impossible to try to work out what the logic is supposed to do here. mi and ph and i oh my. It's just spectacularly impossible to maintain, so avoid doing this: