Mercurial > hg > orthanc-book
comparison Sphinx/source/developers/coding-style.rst @ 0:901e8961f46e
initial commit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 22 Apr 2016 12:57:38 +0200 |
parents | |
children | 25fa874803ab |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:901e8961f46e |
---|---|
1 .. highlight:: c++ | |
2 | |
3 Coding style | |
4 ============ | |
5 | |
6 .. contents:: | |
7 | |
8 The developers of Orthanc should follow these `C++ Programming Style | |
9 Guidelines <http://geosoft.no/development/cppstyle.html>`__, that are | |
10 similar to the so-called "`BSD/Allman style | |
11 <https://en.wikipedia.org/wiki/Indent_style#Allman_style>`__", with | |
12 some adaptations that are described below. A compliant Eclipse | |
13 formatter is `available in the Orthanc distribution | |
14 <https://bitbucket.org/sjodogne/orthanc/src/default/Resources/EclipseCodingStyle.xml>`__. | |
15 | |
16 Licensing | |
17 --------- | |
18 | |
19 Do not forget to include licensing information (GPLv3 with OpenSSL | |
20 exception) in each ``.cpp`` and ``.h``. | |
21 | |
22 Tabulations | |
23 ----------- | |
24 | |
25 No tab characters. Replace 1 tab by 2 spaces. | |
26 | |
27 Strengthened Rules | |
28 ------------------ | |
29 | |
30 * Rule 31: Use ``COLOR_RED`` instead of ``Color::RED`` | |
31 * Rule 34: Use the suffix ``.cpp`` | |
32 * Rule 35: A single header file must contain a single public class | |
33 * Rule 72: Use the Example 2 style (aka. Allman style, used by MSDN | |
34 and Visual Studio):: | |
35 | |
36 while (!done) | |
37 { | |
38 doSomething(); | |
39 done = moreToDo(); | |
40 } | |
41 | |
42 | |
43 Replaced Rules | |
44 -------------- | |
45 | |
46 * Rule 6: The names of the methods are camel-case to move the coding style closer to that of the .NET framework. | |
47 * Rule 36: | |
48 | |
49 * One-liners are always ok in a ``.h``, | |
50 * High-performance code is also allowed but only with the inline | |
51 keyword (the code being moved at the end of the header) | |
52 | |
53 * Rule 40: Use ``#pragma once`` in each header file (cf. `Wikipedia | |
54 <http://en.wikipedia.org/wiki/Pragma_once>`__) | |
55 * Rules 73 and 80: Use Visual Studio's default style that does not add | |
56 two whitespaces in front of public, protected, private and case:: | |
57 | |
58 class SomeClass : public BaseClass | |
59 { | |
60 public: | |
61 ... | |
62 protected: | |
63 ... | |
64 private: | |
65 ... | |
66 }; | |
67 | |
68 | |
69 Additional Rules | |
70 ---------------- | |
71 | |
72 * Use C++ exceptions, avoid error codes. | |
73 * Use the `RAII design pattern <http://en.wikipedia.org/wiki/RAII>`__ (Resource Allocation Is Initialization) wherever possible. | |
74 * No C-style casting, use ``static_cast``, ``reinterpret_cast``, | |
75 ``dynamic_cast`` and ``const_cast``. | |
76 * Never use ``using namespace`` in header files (except inside inline | |
77 implementations). | |
78 * Complement to rule 20: ``Finalize`` is the complementary word to | |
79 ``Initialize``. | |
80 * Minimize the number of #include in header files. | |
81 * Never use ``catch (...)``, except when protecting non-Orthanc code. | |
82 * To ease unit testing, favor the `JavaBeans | |
83 <http://en.wikipedia.org/wiki/Java_beans>`__ conventions: | |
84 | |
85 * Single constructor without argument, | |
86 * Use getters/setters. |