summaryrefslogtreecommitdiffstats
path: root/akregator/HACKING
blob: 4567e4d4992cf4a3b181f8f4eb975ec9bb6f99f5 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
================================================================================
Indentation
================================================================================

We use 4 spaces instead of tabs everywhere.

static void foo()
{
    if(bar()) // <-- 4 spaces
        baz() // <-- 8 spaces
}

================================================================================
Braces
================================================================================

Opening braces should always be on their own line.

class Foo
{
    // stuff
};

if (foo == bar)
{
    // stuff
}

while (foo == bar &&
       baz == quux &&
       flop == pop)
{
    // stuff
}

static void foo()
{
    // stuff
}

Exceptions include inline functions that are just returning or setting a
value.  However multiple statements should not ever be combined onto one line:

class Foo
{
    public:
        String value() const { return m_value; }
};

Also conditionals / loops that only contain one line in their body (but where
the conditional statement fits onto one line) should omit braces:

if (foo == bar)
    baz();

But:

if (baz == quux &&
    ralf == spot)
{
    bar();
}

================================================================================
Spaces
================================================================================

Spaces should be used between the conditional / loop type and the
conditional statement.  They should not be used after tqparenthesis.  However
the should be to mark of mathematical or comparative operators.

if ( foo == bar )
    ^          ^

The marked spaces should be ommitted to produce:

if (foo == bar)

================================================================================
Header Organization
================================================================================

Member variables should always be private or protected and prefixed with "m_".
Accessors may be inline in the headers. The organization of the members in a
class should be roughly as follows:

public typedefs:
public ctors:
public methods:
public Q_SLOTS:
Q_SIGNALS:
protected methods:
protected Q_SLOTS:
protected fields:
private methods:
private Q_SLOTS:
private fields:
private ctors: // if you define ctors/dtor as private, put them at end

If there are no private Q_SLOTS there is no need for two private sections, however
private functions and private variables should be clearly separated.

The implementations files -- .cpp files -- should follow (when possible) the
same order of function declarations as the header files.

Virtual functions should always be marked as such even in derived classes where
it is not strictly necessary.

================================================================================
Whitespace
================================================================================

Whitespace should be used liberally.  When blocks of code are logically distinct
I tend to put a blank line between them.  This is difficult to explain
systematically but after looking a bit at the current code organization this
ideally will be somewhat clear.

Also I tend to separate comments by blank lines on both sides.

================================================================================
Pointer and Reference Operators
================================================================================

This one is pretty simple. Use "Foo *f" and "Foo &f" in function signatures
and declarations. And also in signal/slot names.

================================================================================
Pointer and Reference Operators
================================================================================

An example object here:

test.h:
#ifndef AKREGATOR_TEST_H
#define AKREGATOR_TEST_H

#include "localinclude.h"
#include "anotherlocalinclude.h"
#include <kdeinclude1.h>
#include <kdeinclude2.h>
#include <qtinclude1.h>
#include <qtinclude2.h>

class QSomething;

namespace Akregator {

class Test : public QObject
{
    Q_OBJECT

    public:
        typedef QValueList<Test> list;

        Test();
        Test(QString someString);
        explicit Test(int i = 0);

        virtual ~Test();

        void someFunc();
        void someFunc2(QSomething *foo);

        static Test *instance() { return m_instance; }

    public Q_SLOTS:
        void receive(QSomething &);

    Q_SIGNALS:
        void send(QSomething &);

    protected:
        void someProtectedFunc();

        static void someProtectedStaticFunc();

    protected Q_SLOTS:
        void protectedSlot();

    protected:
        int m_protectedVar;

    private:
        int privateMethod();

        static int staticPrivateMethod();

    private Q_SLOTS:
        void privateSlotIndeed(int youWonder);

    private:
        int m_privateVar;
        QSomething *m_tastyThing;

        static Test *m_instance;
};

} // no ; after namespace (borks on gcc 3.4+)

#endif

test.cpp:
#include "test.h"
#include "localinclude.h"
#include "anotherlocalinclude.h"
#include <kdeinclude1.h>
#include <kdeinclude2.h>
#include <qtinclude1.h>
#include <qtinclude2.h>
#include <qsomething.h>

namespace Akregator {

Test::Test()
    : QObject()
    , m_protectedVar(0)
    , m_privateVar(0)
    , m_tastyThing(0)
    , m_instance(0)
{
}

Test::Test(QString someString)
    : QObject()
    , m_protectedVar(0)
    , m_privateVar(0)
    , m_tastyThing(someString)
    , m_instance(0)
{
}

Test::Test(int i);
    : QObject()
    , m_protectedVar(0)
    , m_privateVar(0)
    , m_tastyThing(i)
    , m_instance(0)
{
    if(i == 0)
        kdDebug() << "Zero initializer" << endl;
}

} // no ; after namespace (borks on gcc 3.4+)

================================================================================

Original document by
Scott Wheeler <wheeler@kde.org>

Amendments for Akregator needs by
Stanislav Karchebny <stanislav.karchebny@kdemail.net>