Commit d67f4cf1 authored by David Jarvie's avatar David Jarvie
Browse files

Add coding guidelines

parent ff6d0140
KAlarmCal coding style
======================
KAlarmCal code should adhere to the following stylistic rules.
SPACING
- No tabs.
- Indent with 4 spaces.
- No spaces inside round or square brackets.
- No space between a function name and the bracket following.
- Place '*' and '&' immediately after the type in declarations, followed by a
space, e.g. "const QString& from", "char* str".
- Normally two spaces on each side of "&&" and "||" in "if"/"while"/"for"
statements.
- Indent "case" within "switch" statements.
BRACES
- Opening brace on a new line.
- No braces are used when only a single statement follows 'if', 'for' etc.
SPLITTING LINES
- There is in general no need to split lines less than 120 characters. Beyond
that length, it's at the coder's discretion.
- Conditional statements occupying line lengths less than 120 characters may be
split for clarity.
- Long "for" statements should be split before each clause at least.
- If a function call or declaration has to be split over more than one line,
indent to after the opening bracket if possible.
- If splitting lines containing expressions, always split BEFORE an operator
("+", "-", "&&" etc.) so that the operator starts the next continuation line.
- In split conditional expressions, position the leading "&&" or "||" before
its enclosing bracket, so that the following expression aligns after the
opening bracket.
NAMING
- Classes, enums, functions and variable names are in camel case (i.e.
separate multiple words by upper-casing each word after the first). Only
use underscores for special purposes.
- Classes and enum names start with an upper case letter.
- Function and variable names start with a lower case letter.
- Enum values are either all upper case with words separated by underscores, or
camel case starting with an upper case letter.
- Constants are all upper case, with words separated by underscores.
- Class member variable names start with "m" followed by a upper case letter.
EXAMPLE
Animal ZooCage::releaseAnimal(const QString& name, Species species,
int arrivalNumber) const
{
if (!name.isEmpty()
&& (arrivalNumber > mMinimumSpeciesCount && arrivalNumber < mMaximumSpeciesCount)
|| !arrivalNumber)
{
mLastReleased = Animal(species, name, arrivalNumber);
return mAnimals[name][arrivalNumber];
}
if (name.isEmpty() || mUnclassifiedAnimals.contains(name))
return mUnclassifiedAnimalTypes[species];
return Animal();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment