File: CODING_STYLE

package info (click to toggle)
kalarm 4%3A25.08.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,904 kB
  • sloc: cpp: 60,440; xml: 1,097; makefile: 9; sh: 2
file content (65 lines) | stat: -rw-r--r-- 2,519 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
KAlarm coding style
===================

KAlarm 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();
}