summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-04-12 16:20:37 +0200
committerLennart Poettering <lennart@poettering.net>2019-04-12 16:28:35 +0200
commit8c9289e705f5a046124e13ccaa6856fd2db9d5bf (patch)
tree78a13dcca26f313de8b94287008f26770fa41c07 /docs
parentCODING_STYLE: add a section about functions not to use (diff)
downloadsystemd-8c9289e705f5a046124e13ccaa6856fd2db9d5bf.tar.xz
systemd-8c9289e705f5a046124e13ccaa6856fd2db9d5bf.zip
CODING_STYLE: split out bits about Formatting into its own section
(And, for now, add a section "Other" to separate the rest of the stuff)
Diffstat (limited to 'docs')
-rw-r--r--docs/CODING_STYLE.md101
1 files changed, 52 insertions, 49 deletions
diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md
index 4238f419de..ed87ae07cc 100644
--- a/docs/CODING_STYLE.md
+++ b/docs/CODING_STYLE.md
@@ -4,14 +4,16 @@ title: Coding Style
# Coding Style
+## Formatting
+
- 8ch indent, no tabs, except for files in `man/` which are 2ch indent, and
still no tabs, and shell scripts, which are 4ch indent, and no tabs either.
-- We prefer `/* comments */` over `// comments` in code you commit, please. This
- way `// comments` are left for developers to use for local, temporary
- commenting of code for debug purposes (i.e. uncommittable stuff), making such
- comments easily discernible from explanatory, documenting code comments
- (i.e. committable stuff).
+- We prefer `/* comments */` over `// comments` in code you commit,
+ please. This way `// comments` are left for developers to use for local,
+ temporary commenting of code for debug purposes (i.e. uncommittable stuff),
+ making such comments easily discernible from explanatory, documenting code
+ comments (i.e. committable stuff).
- Don't break code lines too eagerly. We do **not** force line breaks at 80ch,
all of today's screens should be much larger than that. But then again, don't
@@ -21,6 +23,51 @@ title: Coding Style
note that emacs loads `.dir-locals.el` automatically, but vim needs to be
configured to load `.vimrc`, see that file for instructions.
+- Try to write this:
+
+ ```c
+ void foo() {
+ }
+ ```
+
+ instead of this:
+
+ ```c
+ void foo()
+ {
+ }
+ ```
+
+- Single-line `if` blocks should not be enclosed in `{}`. Write this:
+
+ ```c
+ if (foobar)
+ waldo();
+ ```
+
+ instead of this:
+
+ ```c
+ if (foobar) {
+ waldo();
+ }
+ ```
+
+- Do not write `foo ()`, write `foo()`.
+
+- Preferably allocate local variables on the top of the block:
+
+ ```c
+ {
+ int a, b;
+
+ a = 5;
+ b = a;
+ }
+ ```
+
+## Other
+
- Variables and functions **must** be static, unless they have a
prototype, and are supposed to be exported.
@@ -83,50 +130,6 @@ title: Coding Style
numbers. Their syntax is locale dependent (i.e. `5.000` in en_US is
generally understood as 5, while in de_DE as 5000.).
-- Try to use this:
-
- ```c
- void foo() {
- }
- ```
-
- instead of this:
-
- ```c
- void foo()
- {
- }
- ```
-
- But it is OK if you do not.
-
-- Single-line `if` blocks should not be enclosed in `{}`. Use this:
-
- ```c
- if (foobar)
- waldo();
- ```
-
- instead of this:
-
- ```c
- if (foobar) {
- waldo();
- }
- ```
-
-- Do not write `foo ()`, write `foo()`.
-
-- Preferably allocate stack variables on the top of the block:
-
- ```c
- {
- int a, b;
-
- a = 5;
- b = a;
- }
- ```
- Unless you allocate an array, `double` is always a better choice
than `float`. Processors speak `double` natively anyway, so there is