2 ---------------------------------------------------------------------
3 Here will you find coding standards to the project. Requirements are
4 listed in their respective files and can be considered an adendum to
9 ---------------------------------------------------------------------
10 See linux/Documentation/CodingStyle.
14 - Outside of comments and documentation, never
15 use spaces. Identation is done using tabs only.
17 - Do not use tabs to align text documentation. Changing tab
18 width should not interfere with the layout/alignment of code,
21 - functions are declared like this:
22 char *function(const char *test)
27 - if you use brackets INSIDE a function put them on the same line
40 - Do not put actions in the same line of conditions:
43 if (condition) do_this;
49 - Also it is a good practice to use always brackets in conditions:
55 - Variables are always in lower case (like tmp_buf)
56 - New defined types are capitalized (like OSyncEngine)
57 - Never use typedefs just to hide pointers
59 - External APIs, used for integration between components may
64 - Always add the osync_ prefix to your functions
66 - Do not return function calls, like "return do_something();",
67 instead, use a auxiliar variable (rationale: easy trace).
69 - When doing error checking, use goto to help creating a single
70 return point. Do not abuse goto usage though... never goto up,
71 never create more than one label and do not "gotoo far".
75 ---------------------------------------------------------------------
77 * Add FIXME, TODO and XXX comments appropriately.
79 * Use Doxygen (http://www.stack.nl/~dimitri/doxygen/) to document your code
81 * Add your doxygen annotations in the header files. This allows other
82 developers to read the documentation without having installed the source.
84 * Add simple READMEs and pictures as needed, but concentrate
88 -----------------------------------------------------------------
92 * Use static for internal functions;
93 * Use safe glib functions where possible;
94 * Check validity of all received parameters;
95 * Use osync_assert() while developing;
96 * Do not use alloca() or other non-recommended functions;
97 * Check for return errors even from malloc() and other
98 standard system calls;
101 * Use valgrind to profile you application and find memleaks
104 * Source code has to be split into modules, which are defined as
105 a collection of implementation files (.c) with an interface
106 exported through a header file (.h).
107 * The inclusion (#include) of headers must reflect the dependencies
108 between modules in the implementation. The most important
109 implications from this statement are:
111 . implementation files (.c) *must* include *all* headers it
113 . implementation files (.c) *must not* include headers it
114 doesn't directly depend;
115 . headers should include headers only when needing a
116 definition or declaration;
117 . headers should never include other headers just to create a
118 "single point of inclusion".
120 These rules may sound obvious, but they're actually hard to
124 COMMITS AND CHANGELOGS
125 ---------------------------------------------------------------------
126 Descriptive and small.
129 - *Always* do a svn diff and a svn status before a commit and
130 document the diff(s) in the changelogs;
131 - What matters is not what but why;
132 - Several commits are usually better than a big one;
133 - Do not commit unrelated modifications at once unless they're
138 ---------------------------------------------------------------------
139 Standard instructions:
141 Code should compile with no warnings, using the following GCC
147 Recomended but not mandatory (for now):
149 -Wmissing-declarations
159 For developers using GCC there is a CMAKE_BUILD_TYPE "hacking" which sets
160 the default compiler flags to a recommended compiler flag set.
163 ---------------------------------------------------------------------
164 There are two types of logs that must be handled by almost all
167 * HIGH-LEVEL LOGS: these are standard, high-level logs usually
168 enabled by default. Useful to advanced users, support-centers and
169 alike. Should include basic information, including but not limited
171 - start/end of application
175 The requirements document specifies if logs are needed or not.
177 * TRACES: traces are a particular kind of log used to debug the
178 application. They're used mostly by black-box testers to submit
181 Traces should be enabled in a per-application basis using an
182 envinronment variable or at compile time, to be yet defined.
185 -----------------------------------------------------------------
187 * All code should be written together with unit-tests. The tool
188 used to implement the tests is "check", available on
189 http://check.sourceforge.net/.
191 The build-system infra-structure provides a configure option to
194 The tests must be implemented inside a sub-directory called test
195 with the following modules:
197 check_<component name> --> the test-manager
198 check_<unit name> --> implements tests for interfaces
202 Just to remember, an unit, or module, is a collection of
203 souce-code files (.c) with an interface exported through
206 All interfaces exported by units must be tested (that is,
207 all non-static functions). The tests should implement at
208 least the following test cases:
211 - upper and bottom limits of buffers and variables as
216 Use incremental tests, that is, test functions before using them in
217 other test-cases (for example, if you need to call function A to
218 prepare the environment to test function B, test function A first).
220 Try to write the test-case before the unit or function itself.
222 If the test needs an external entity to work (for example, it needs
223 a device connected on a specific port), put the test inside a
224 condition for an environemnt variable and document it in a README