TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. ================================================================================
  2. Indentation
  3. ================================================================================
  4. We use 4 spaces instead of tabs everywhere.
  5. static void foo()
  6. {
  7. if(bar()) // <-- 4 spaces
  8. baz() // <-- 8 spaces
  9. }
  10. ================================================================================
  11. Braces
  12. ================================================================================
  13. Opening braces should always be on their own line.
  14. class Foo
  15. {
  16. // stuff
  17. };
  18. if (foo == bar)
  19. {
  20. // stuff
  21. }
  22. while (foo == bar &&
  23. baz == quux &&
  24. flop == pop)
  25. {
  26. // stuff
  27. }
  28. static void foo()
  29. {
  30. // stuff
  31. }
  32. Exceptions include inline functions that are just returning or setting a
  33. value. However multiple statements should not ever be combined onto one line:
  34. class Foo
  35. {
  36. public:
  37. String value() const { return m_value; }
  38. };
  39. Also conditionals / loops that only contain one line in their body (but where
  40. the conditional statement fits onto one line) should omit braces:
  41. if (foo == bar)
  42. baz();
  43. But:
  44. if (baz == quux &&
  45. ralf == spot)
  46. {
  47. bar();
  48. }
  49. ================================================================================
  50. Spaces
  51. ================================================================================
  52. Spaces should be used between the conditional / loop type and the
  53. conditional statement. They should not be used after parenthesis. However
  54. the should be to mark of mathematical or comparative operators.
  55. if ( foo == bar )
  56. ^ ^
  57. The marked spaces should be ommitted to produce:
  58. if (foo == bar)
  59. ================================================================================
  60. Header Organization
  61. ================================================================================
  62. Member variables should always be private or protected and prefixed with "m_".
  63. Accessors may be inline in the headers. The organization of the members in a
  64. class should be roughly as follows:
  65. public typedefs:
  66. public ctors:
  67. public methods:
  68. public slots:
  69. signals:
  70. protected methods:
  71. protected slots:
  72. protected fields:
  73. private methods:
  74. private slots:
  75. private fields:
  76. private ctors: // if you define ctors/dtor as private, put them at end
  77. If there are no private slots there is no need for two private sections, however
  78. private functions and private variables should be clearly separated.
  79. The implementations files -- .cpp files -- should follow (when possible) the
  80. same order of function declarations as the header files.
  81. Virtual functions should always be marked as such even in derived classes where
  82. it is not strictly necessary.
  83. ================================================================================
  84. Whitespace
  85. ================================================================================
  86. Whitespace should be used liberally. When blocks of code are logically distinct
  87. I tend to put a blank line between them. This is difficult to explain
  88. systematically but after looking a bit at the current code organization this
  89. ideally will be somewhat clear.
  90. Also I tend to separate comments by blank lines on both sides.
  91. ================================================================================
  92. Pointer and Reference Operators
  93. ================================================================================
  94. This one is pretty simple. Use "Foo *f" and "Foo &f" in function signatures
  95. and declarations. And also in signal/slot names.
  96. ================================================================================
  97. Pointer and Reference Operators
  98. ================================================================================
  99. An example object here:
  100. test.h:
  101. #ifndef AKREGATOR_TEST_H
  102. #define AKREGATOR_TEST_H
  103. #include "localinclude.h"
  104. #include "anotherlocalinclude.h"
  105. #include <kdeinclude1.h>
  106. #include <kdeinclude2.h>
  107. #include <qtinclude1.h>
  108. #include <qtinclude2.h>
  109. class QSomething;
  110. namespace Akregator {
  111. class Test : public QObject
  112. {
  113. Q_OBJECT
  114. public:
  115. typedef QValueList<Test> list;
  116. Test();
  117. Test(QString someString);
  118. explicit Test(int i = 0);
  119. virtual ~Test();
  120. void someFunc();
  121. void someFunc2(QSomething *foo);
  122. static Test *instance() { return m_instance; }
  123. public slots:
  124. void receive(QSomething &);
  125. signals:
  126. void send(QSomething &);
  127. protected:
  128. void someProtectedFunc();
  129. static void someProtectedStaticFunc();
  130. protected slots:
  131. void protectedSlot();
  132. protected:
  133. int m_protectedVar;
  134. private:
  135. int privateMethod();
  136. static int staticPrivateMethod();
  137. private slots:
  138. void privateSlotIndeed(int youWonder);
  139. private:
  140. int m_privateVar;
  141. QSomething *m_tastyThing;
  142. static Test *m_instance;
  143. };
  144. } // no ; after namespace (borks on gcc 3.4+)
  145. #endif
  146. test.cpp:
  147. #include "test.h"
  148. #include "localinclude.h"
  149. #include "anotherlocalinclude.h"
  150. #include <kdeinclude1.h>
  151. #include <kdeinclude2.h>
  152. #include <qtinclude1.h>
  153. #include <qtinclude2.h>
  154. #include <qsomething.h>
  155. namespace Akregator {
  156. Test::Test()
  157. : QObject()
  158. , m_protectedVar(0)
  159. , m_privateVar(0)
  160. , m_tastyThing(0)
  161. , m_instance(0)
  162. {
  163. }
  164. Test::Test(QString someString)
  165. : QObject()
  166. , m_protectedVar(0)
  167. , m_privateVar(0)
  168. , m_tastyThing(someString)
  169. , m_instance(0)
  170. {
  171. }
  172. Test::Test(int i);
  173. : QObject()
  174. , m_protectedVar(0)
  175. , m_privateVar(0)
  176. , m_tastyThing(i)
  177. , m_instance(0)
  178. {
  179. if(i == 0)
  180. kdDebug() << "Zero initializer" << endl;
  181. }
  182. } // no ; after namespace (borks on gcc 3.4+)
  183. ================================================================================
  184. Original document by
  185. Scott Wheeler <wheeler@kde.org>
  186. Amendments for Akregator needs by
  187. Stanislav Karchebny <stanislav.karchebny@kdemail.net>