Coding Conventions - Umcaruje/lmms GitHub Wiki
Everybody has their own favorite "style" for writing code, however, in the interest of making the codebase easier to maintain, we request that the following conventions be observed. Code that is lifted from other projects does not need to be modified to match these rules – no need to fix what isn't broken.
All indentation is performed using tabs.
Mixing tabs and spaces is evil. Please, please, please make sure your editor is configured to use tabs. Instructions for QtCreator can be found here.
Try to limit line lengths to 80 characters
Not an absolute requirement – sometimes longer lines can't be avoided. But it is a friendly thing to do.
Do not prefix header guard macros with an underscore
Header guards should not begin with an underscore. Identifiers that begin with an underscore + capital letter are reserved identifiers in C++ and their usage should be avoided. If you edit an older file which contains an improper header guard, please fix it to comply with guidelines.
All kind of types (class names, enums, structs) begin with an upper case letter
Example:
class ResourcesDB;
enum MyEnum
{
ListItem1,
ListItem2,
...
} ;
typedef QList<AutomatableModel *> AutoModelList;
Variable and method names begin with a lower case letter
Example:
void doThis(int a);
int myLocalVariable;
Member variables are prefixed with "m_"
Example:
Knob * m_chordRangeKnob;
Function parameters are not prefixed with "_" anymore
Example:
void clearS16Buffer(outputSampleType* outbuf, Uint32 frames)
*Infix operators (=, +, -, , /, etc.) should have a space before and after
Example:
sub_note_key_base = base_note_key + octave_cnt * NOTES_PER_OCTAVE;
if
, else
, for
, and while
should use explicit blocking
Example:
if(m_sample > 0)
{
--m_sample;
}
If you can comfortably fit the block on one line, then it's acceptable to format it like this:
if(m_sample > 0) { --m_sample; }
...but note that the braces must always be included!
Make sure, there're 4 lines of space between functions declarations
Example:
void foo(int bar)
{
...
}
void bar(int foo)
{
...
}
Return without parenthesis (NEW)
Example:
int foo()
{
return bar;
}
Standard true/false constants (NEW)
Example:
if(a == true)
{
b = false;
}
Ternary operators: generally, you should only use them when it makes sense, when it makes the code more streamlined or more readable. If you have to use long ternary expressions that don't fit on one line, they should be formatted like this:
a == condition
? value
: otherValue;
However, if the expressions are very long or convoluted, consider using if/else blocks instead.
In general, please make a bit of an effort to try to keep things looking the way they already do. Individual creativity is good, but coordinated creativity gets things done faster.