File: CODING_GUIDELINES.md

package info (click to toggle)
mumble 1.5.735-7
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 90,032 kB
  • sloc: cpp: 556,923; ansic: 81,662; python: 3,606; sh: 659; makefile: 506; asm: 371; cs: 306; sql: 228; javascript: 143; perl: 80; xml: 13
file content (50 lines) | stat: -rw-r--r-- 2,063 bytes parent folder | download | duplicates (4)
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
# Mumble coding guidelines

## Formatting

We use [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to format our source code. The details of the formatting are fixed in the
`.clang-format` file at the root of this repository.

When making changes to the source code, please always reformat the changed files using this tool in order to ensure a consistent formatting across the
code base.


## Use of `auto`

Since we are using a more modern C++ standard, the usage of the `auto` keyword is in principle possible. However we have decided that for the sake of
readability of the code we want to restrict its usage to the following cases:
1. Usage of STL-iterators
2. If the expression of the assignment already contains the type explicitly (e.g. because of a cast or by usage of e.g. `make_unique`)

An example of the first scenario would be
```cpp
auto it = myVector.begin();
```
And examples for the second case are
```cpp
auto myObj   = new MyObject();
auto myOther = std::make_unique< MyOther >();
auto number  = static_cast< int >(1.5);
```


## Smart pointers

You should always prefer smart-pointers over raw pointers. The general rule is: Never use `new` and `delete` explicitly.

Also prefer `std::unique_ptr` over `std::shared_ptr`, unless you are really intending for the object to have shared ownership.

When it comes to passing pointers into functions, always pass as raw-pointer, unless you want to transfer ownership of the pointer to the function.


## Pointer vs. Reference

Use pointers only if `nullptr` is a valid option (and is therefore explicitly checked for). Whenever you are expecting that a passed value is set,
pass that value by reference instead in order to make sure that the semantics forbid passing `nullptr` to the function.


## Qt vs. STL

Wherever feasible, you should prefer using types from the standard library (STL) instead of Qt-specific ones. Note that this only applies if you don't
have to pass that type (indirectly) into Qt functions that only accept Qt-specific types. In these cases, prefer Qt-types.