uname: move under bmake, remove setuname(1m)
[unleashed.git] / docs / clean-code.md
blobb65f60fd54e10b4251e2df94432e04f61e9d1c76
1 Clean Code Best Practices
2 =========================
4 This document describes some of the practices we use to maintain high code
5 quality.
7 Debug-only build variables
8 --------------------------
10 If you have any variables that are used only in a debug build, don't leave
11 them unused outside of debug builds.
13 The following is *bad* because it leaves an unused variable, which forces
14 the entire build to use `-Wno-unused-variable`:
16 ```
17 int foobar(int arg)
19         int foo;
21 #ifdef DEBUG
22         foo = checkarg(arg);
23         if (foo != 42)
24                 return -1;
25 #endif
27         bar(arg);
29         return 0;
31 ```
33 To solve it, make the definition of `foo` part of the `#ifdef` or in this
34 case eliminate it completely and check the return value of `checkarg`
35 directly:
37 ```
38 int foobar(int arg)
40 #ifdef DEBUG
41         if (checkarg(arg) != 42)
42                 return -1;
43 #endif
45         bar(arg);
47         return 0;
49 ```