Migrate to openssl 3
[platform/upstream/glib-networking.git] / HACKING.md
1 # Code Style
2
3 In order to keep the code nice and clean we have a few requirements you'll
4 need to stick to in order to get your patch accepted:
5
6  * Use GNU-style indentation:
7
8    ```
9    if (condition)
10      {
11        // body
12      }
13    ```
14
15  * No braces for one line control clauses, except when another clause in the
16    chain contains more than one line:
17
18   ```
19   if (condition)
20     look_no_braces ();
21
22   if (condition)
23     {
24       // Use braces even though it's only one statement, because
25       // the condition is multiple lines long.
26       function_call_with_many_arguments (arg1, arg2, arg3,
27                                          arg4, arg5, arg6);
28     }
29   else
30     {
31       // Use braces because the clause above did.
32     }
33   ```
34
35  * Callback functions have a suffix _cb. TODO: ensure existing code follows this
36    rule.
37
38  * Use `char`/`int`/`double`/…, not `gchar`/`gint`/`gdouble`/… types, except
39    when implementing GLib vfuncs that use these types. TODO: ensure existing
40    code follows this rule.
41
42  * All implementation files must include first `"config.h"`, followed by
43    the primary header, followed by a blank line, followed by all the
44    local headers sorted alphabetically, followed by a blank line,
45    followed by all the system headers sorted alphabetically. Headers
46    should follow the same pattern excluding the config.h and
47    self file section, for obvious reasons. TODO: ensure existing code follows
48    this rule.
49
50  * There's no space between a type cast and the variable name:  Right:
51    `(int *)foo`. Wrong: `(int*) foo`.
52
53  * Avoid explicit comparisons against TRUE, FALSE, and NULL. Right:
54    `if (!condition)`, `if (!pointer)`, `if (integer == 0)`. Wrong:
55    `if (condition == FALSE)`, `if (pointer == NULL)`, `if (!integer)`.
56    Exception: `pointer != NULL` may be used to convert to gboolean since some
57    developers find this more natural than `!!pointer`.