summaryrefslogtreecommitdiff
path: root/docs/CODING_STYLE.md
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-01-17 15:49:01 +0100
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-01-17 21:26:13 +0100
commitf591cf66f0fb1024f68e23fdd9c024eb41dd3a4a (patch)
treef2b91591b8705f6a0e596cfebb2355fed983c2af /docs/CODING_STYLE.md
parentbb4e8820c17c70d1cd10612c02a5cc726e3c8f06 (diff)
downloadsystemd-f591cf66f0fb1024f68e23fdd9c024eb41dd3a4a.tar.gz
doc: document how we expect empty lines to be used
Diffstat (limited to 'docs/CODING_STYLE.md')
-rw-r--r--docs/CODING_STYLE.md18
1 files changed, 16 insertions, 2 deletions
diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md
index c96325b3fe..e86b41eb4a 100644
--- a/docs/CODING_STYLE.md
+++ b/docs/CODING_STYLE.md
@@ -120,6 +120,19 @@ SPDX-License-Identifier: LGPL-2.1-or-later
`_SD_ENUM_FORCE_S64()` macro in the enum definition, which forces the size of
the enum to be signed 64bit wide.
+- Empty lines to separate code blocks are a good thing, please add them
+ abundantly. However, please stick to one at a time, i.e. multiple empty lines
+ immediately following each other are not OK. Also, we try to keep function calls and their immediate error handling together. Hence:
+
+ ```c
+ /* → empty line here is good */
+ r = some_function(…);
+ /* → empty line here would be bad */
+ if (r < 0)
+ return log_error_errno(r, "Some function failed: %m");
+ /* → empty line here is good */
+ ```
+
## Code Organization and Semantics
- For our codebase we intend to use ISO C11 *with* GNU extensions (aka
@@ -210,8 +223,9 @@ SPDX-License-Identifier: LGPL-2.1-or-later
the point where they can be initialized. Avoid huge variable declaration
lists at the top of the function.
- As an exception, `r` is typically used for a local state variable, but should
- almost always be declared as the last variable at the top of the function.
+ As an exception, `int r` is typically used for a local state variable, but
+ should almost always be declared as the last variable at the top of the
+ function.
```c
{