Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung | |||
|
private:codingstyle [2013/04/19 13:27] Patrick Wacker weitere überarbeitung |
private:codingstyle [2013/04/19 15:07] (aktuell) Patrick Wacker dies und das |
||
|---|---|---|---|
| Zeile 9: | Zeile 9: | ||
| < tab! | < tab! | ||
| + | |||
| + | ====== Version 1 ====== | ||
| + | short explanation | ||
| + | ################################################################################ | ||
| ====== Coding Style ====== | ====== Coding Style ====== | ||
| Zeile 40: | Zeile 44: | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ====== Version 2 ====== | ||
| + | mostly from: http://techbase.kde.org/Policies/Kdelibs_Coding_Style | ||
| + | ################################################################################ | ||
| + | |||
| + | |||
| + | ===== Coding style ===== | ||
| + | |||
| + | This documents describes the coding style I prefer. Coding style is very | ||
| + | personal, and I won't force my views on anybody, but this is what goes for | ||
| + | anything that I have to be able to maintain, and I'd prefer it for most | ||
| + | other things too. | ||
| + | |||
| + | Please at least consider the points made here. | ||
| + | |||
| + | |||
| + | ==== Indentation ==== | ||
| + | |||
| + | * use tabs for indentation | ||
| + | * tabs are 8 characters, and thus indentations are also 8 characters. | ||
| + | |||
| + | ==== Variable declaration ==== | ||
| + | |||
| + | * Each new word in a variable name starts with a capital letter\\ (so-called camelCase) | ||
| + | * Avoid abbreviations | ||
| + | * Take usefull names. No short names, except: | ||
| + | * singe character variable names can denote counters and temporary\\ variables whose purpose is obvious | ||
| + | * Variables and functions start with a lowercase letter | ||
| + | |||
| + | ==== Whitespace ==== | ||
| + | |||
| + | * Use blank lines to group statements | ||
| + | * Use only one empty line | ||
| + | * Use one space after each keyword | ||
| + | * For pointers or references, use a single space before '*' or '&', but not after | ||
| + | * No space after a cast | ||
| + | |||
| + | ==== Braces ==== | ||
| + | |||
| + | As a base rule, the left curly brace goes in the same line as the start of the statement. | ||
| + | |||
| + | Example: | ||
| + | // wrong | ||
| + | if (true) | ||
| + | { | ||
| + | } | ||
| + | |||
| + | // correct | ||
| + | if (true) { | ||
| + | } | ||
| + | |||
| + | Exception: Function implemnetations, class, struct and namespace declarations always have the opening brace in the start of a line. | ||
| + | |||
| + | Example: | ||
| + | void debug(int i) | ||
| + | { | ||
| + | qDebug("foo: %i", i); | ||
| + | } | ||
| + | |||
| + | class Debug | ||
| + | { | ||
| + | }; | ||
| + | |||
| + | |||
| + | Do not unnecessarily use braces where a single statement will do. | ||
| + | |||
| + | if (condition) | ||
| + | action(); | ||
| + | |||
| + | and | ||
| + | |||
| + | if (condition) | ||
| + | do_this(); | ||
| + | else | ||
| + | do_that(); | ||
| + | |||
| + | This does not apply if one branch of a conditional statement is a | ||
| + | single statement. Use braces in both branches. | ||
| + | |||
| + | if (condition) { | ||
| + | do_this(); | ||
| + | do_that(); | ||
| + | } else { | ||
| + | otherwise(); | ||
| + | } | ||
| + | |||
| + | |||
| + | ==== Switch statements ==== | ||
| + | |||
| + | Case labels are on the same column as the switch | ||
| + | |||
| + | switch (myEnum) { | ||
| + | case Value1: | ||
| + | doSomething(); | ||
| + | break; | ||
| + | case Value2: | ||
| + | doSomethingElse(); | ||
| + | /* fall through */ | ||
| + | default: | ||
| + | defaultHandling(); | ||
| + | break; | ||
| + | } | ||
| + | |||
| + | ==== Line breaks ==== | ||
| + | |||
| + | Try to keep lines shorter than 80 characters, insert line breaks as necessary. | ||
| + | |||
| + | Long strings are as well broken into shorter strings. The exception to this | ||
| + | is where exceeding 80 columns significantly increases readability and does | ||
| + | not hide information. | ||
| Zeile 45: | Zeile 162: | ||
| + | ====== Version 3 ====== | ||
| + | mostly from linux kernel | ||
| + | ################################################################################ | ||
| Zeile 304: | Zeile 424: | ||
| + | ====== Version 4 ====== | ||
| + | original linux kernel | ||
| + | ################################################################################ | ||