this folders -> this folder
[kdepim.git] / akregator / HACKING
blob46f78ed103d7f53468acfde168cdeab9adcab4f4
1 ================================================================================
2 Indentation
3 ================================================================================
5 We use 4 spaces instead of tabs everywhere.
7 static void foo()
9     if(bar()) // <-- 4 spaces
10         baz() // <-- 8 spaces
13 ================================================================================
14 Braces
15 ================================================================================
17 Opening braces should always be on their own line.
19 class Foo
21     // stuff
24 if (foo == bar)
26     // stuff
29 while (foo == bar &&
30        baz == quux &&
31        flop == pop)
33     // stuff
36 static void foo()
38     // stuff
41 Exceptions include inline functions that are just returning or setting a
42 value.  However multiple statements should not ever be combined onto one line:
44 class Foo
46     public:
47         String value() const { return m_value; }
50 Same goes for the main namespace of a header (the namespace where the class 
51 declaration is in, opposed to forward declaration (see also "Namespaces")
52         
53 ================================================================================
54 Spaces
55 ================================================================================
57 Spaces should be used between the conditional / loop type and the
58 conditional statement. They should not be used after parenthesis. However
59 the should be to mark of mathematical or comparative operators.
61 if ( foo == bar )
62     ^          ^
64 The marked spaces should be ommitted to produce:
66 if (foo == bar)
68 ================================================================================
69 Header Organization
70 ================================================================================
72 Guards:
73         
74 For test.h, declaring the class Akregator::Test, use AKREGATOR_TEST_H, not TEST_H,
75 nor _AKREGATOR_TEST_H_ etc. Comment the closing #endif.
77 #ifndef AKREGATOR_TEST_H
78 #define AKREGATOR_TEST_H
79 ...
80 #endif // AKREGATOR_TEST_H
81         
82 Member variables should always be private or protected and prefixed with "m_".
83 Accessors may be inline in the headers. The organization of the members in a
84 class should be roughly as follows:
86 public typedefs:
87 public ctors/dtors:
88 public methods:
89 public slots:
90 signals:
91 protected methods:
92 protected slots:
93 protected fields:
94 private ctors/dtors:
95 private methods:
96 private slots:
97 private fields:
100 If there are no private slots there is no need for two private sections, however
101 private functions and private variables should be clearly separated.
103 The implementations files -- .cpp files -- should follow (when possible) the
104 same order of function declarations as the header files.
106 Virtual functions should always be marked as such even in derived classes where
107 it is not strictly necessary.
109 ================================================================================
110 Namespaces
111 ================================================================================
113 - Do not indent stuff in the "main namespace" of a file. But do for forward declarations.
114 - comment the closing bracket of the namespace with // namespace Foo
116 Example:
117         
118 namespace KParts
120     class ReadOnlyPart;
122 namespace Akregator {
124 class Foo
128 } // namespace Akregator
130 ================================================================================
131 Whitespace
132 ================================================================================
134 Whitespace should be used liberally.  When blocks of code are logically distinct
135 I tend to put a blank line between them.  This is difficult to explain
136 systematically but after looking a bit at the current code organization this
137 ideally will be somewhat clear.
139 Also I tend to separate comments by blank lines on both sides.
141 ================================================================================
142 Pointer and Reference Operators
143 ================================================================================
145 Use "Foo* f" and "Foo& f" in function signatures and declarations. And also in 
146 signal/slot names.
148 ================================================================================
149 Signals and Slots
150 ================================================================================
152 Prefix slots/signals with "slot"/"signal". Fully qualify types used in arguments
153 (i.e. add namespaces).
155 Example:
156         
158         
159     signals:
160         
161         signalFoo(const Akregator::Article&);
162         
164         
165     signals:
166         
167         foo(const Article&);
169 ================================================================================
170 Pointer and Reference Operators
171 ================================================================================
173 An example object here:
175 test.h:
176 #ifndef AKREGATOR_TEST_H
177 #define AKREGATOR_TEST_H
179 #include "localinclude.h"
180 #include "anotherlocalinclude.h"
181 #include <kdeinclude1.h>
182 #include <kdeinclude2.h>
183 #include <qtinclude1.h>
184 #include <qtinclude2.h>
186 class QSomething;
188 namespace Akregator {
190 class Test : public QObject
192     Q_OBJECT
194     public:
195         typedef QValueList<Test> list;
197         Test();
198         Test(QString someString);
199         explicit Test(int i = 0);
201         virtual ~Test();
203         void someFunc();
204         void someFunc2(QSomething *foo);
206         static Test *instance() { return m_instance; }
208     public slots:
209         void receive(QSomething &);
211     signals:
212         void send(QSomething &);
214     protected:
215         void someProtectedFunc();
217         static void someProtectedStaticFunc();
219     protected slots:
220         void protectedSlot();
222     protected:
223         int m_protectedVar;
225     private:
226         int privateMethod();
228         static int staticPrivateMethod();
230     private slots:
231         void privateSlotIndeed(int youWonder);
233     private:
234         int m_privateVar;
235         QSomething* m_tastyThing;
237         static Test* m_instance;
240 } // no ; after namespace (borks on gcc 3.4+)
242 #endif
244 test.cpp:
245 #include "test.h"
246 #include "localinclude.h"
247 #include "anotherlocalinclude.h"
248 #include <kdeinclude1.h>
249 #include <kdeinclude2.h>
250 #include <qtinclude1.h>
251 #include <qtinclude2.h>
252 #include <qsomething.h>
254 namespace Akregator {
256 Test::Test()
257     : QObject()
258     , m_protectedVar(0)
259     , m_privateVar(0)
260     , m_tastyThing(0)
261     , m_instance(0)
265 Test::Test(QString someString)
266     : QObject()
267     , m_protectedVar(0)
268     , m_privateVar(0)
269     , m_tastyThing(someString)
270     , m_instance(0)
274 Test::Test(int i);
275     : QObject()
276     , m_protectedVar(0)
277     , m_privateVar(0)
278     , m_tastyThing(i)
279     , m_instance(0)
281     if (i == 0)
282         kDebug() << "Zero initializer";
285 } // namespace Akregator
287 ================================================================================
289 Original document by
290 Scott Wheeler <wheeler@kde.org>
292 Amendments for Akregator needs by
293 Stanislav Karchebny <stanislav.karchebny@kdemail.net>
294 Frank Osterfeld <osterfeld@kde.org>