summaryrefslogtreecommitdiff
path: root/CODING_STYLE
blob: 3b0b93db89e7ebe18b780ff7fc5399b02ce31ccd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Coding style
============

Many parts of the NodeHealthMonitor (NHM) are using the interface of the GNOME 
glib library and the gdbus binding. Because of the many glib calls, it made 
sense to align the remaining NHM code in a similar style. Please make sure to 
follow the definitions here, to make the code more easy to maintain!

Project structure
-----------------

The sources of the NHM are located in different subfolders, based on their 
content. The following subfolders are used:

  cfg: initial configuration, systemd service files, "package config" file 
       and other administrative files.
  doc: Documentation
  gen: Destination for generated code.
  inc: Public header files (see chapter 5.2).
  mod: models to generate code (e.g. dbus XML interfaces).
  src: Source code of the NHM.
  tst: Unit test for the NHM and stubs to replace system functions.

The C source code of the project should be devided into seperate files. 
The source files should start with a comment, describing what they represent.

Naming conventions
------------------

  - The source files should be named "nhm-<purpose>", where purpose describes 
    the functionality that the file implements. 
  - The functions/symbols should be named "nhm_<purpose>_<symbol>".
  - There is no hungarian notation.


Variable declaration
--------------------

Local variables may only be declared at the beginning of a function.


Line width
----------

The monitors are getting bigger, but the integrated development environments 
(IDE) are getting more windows. Therefore, maximum line width should be 80 
wherever possible.


Intendation
-----------

The intendation is two spaces, no tabs.


Braces
------

  - All curly braces come into the next line (except for variable initializers) 
  - Curly braces are not intended


if/else statements
------------------

  - All branches should be surrounded by curly braces.


Comments
--------

Only the C89 comment symbols "/* */" may be used.


White spaces
------------

There is no whitspace before parenthesis:

  /* good */
  void nhm_example_print_some_numbers()
  {
    for(i = 0; i < 1000; i++)
    {
      if(i % 10 == 0)
      {
        printf("%i\n", i);
      }
    }
  }


switch/case statements
----------------------

The "break" should have the same intendation level as the "case" 
to which it belongs:
    
  /* good */
  void nhm_example_define_to_text(const gint def)
  {
    switch(def)
    {
      case TEST1:
        g_print("Test 1\n");
      break;

      case TEST2:
        g_print("Test 2\n");
      break;

      default:
        g_print("unknown\n");
      break;
    }
  }