You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CODING_GUIDELINES.md
+32-47Lines changed: 32 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,8 +29,10 @@ class MyOtherClass
29
29
{
30
30
public:
31
31
//code
32
+
32
33
protected:
33
34
//code
35
+
34
36
private:
35
37
//code
36
38
};
@@ -87,10 +89,14 @@ default:
87
89
}
88
90
```
89
91
90
-
#### d. single-line blocks (lambdas, initializer lists etc.) ####
92
+
#### d. Brace enclosed initializers ####
93
+
Unlike single-line functions, you must not insert spaces between the brackets and concluded expressions.<br/>
94
+
But you must insert a space between the variable name and initializer.
91
95
```c++
92
-
{} // empty - space before {
93
-
{ body } // spaces around { and before }
96
+
Class obj {}; // empty
97
+
Class obj {expr};
98
+
Class obj {expr1, /*...,*/ exprN};
99
+
QVariantMap map {{"key1", 5}, {"key2", 10}};
94
100
```
95
101
96
102
### 2. If blocks ###
@@ -173,11 +179,11 @@ All names should be camelCased.
173
179
#### a. Type names and namespaces ####
174
180
Type names and namespaces start with Upper case letter (except POD types).
175
181
```c++
176
-
classClassName {}
182
+
classClassName {};
177
183
178
-
struct StructName {}
184
+
struct StructName {};
179
185
180
-
enum EnumName {}
186
+
enum EnumName {};
181
187
182
188
typedef QList<ClassName> SomeList;
183
189
@@ -211,47 +217,18 @@ a += "b"
211
217
+ "d";
212
218
```
213
219
214
-
* Initializers
215
-
216
-
We allow brace enclosed initializers only for aggregates and arrays/containers.<br />
217
-
Brace enclosed initializer MUST be used with equality sign if it follows the variable declaration.<br />
218
-
Brace enclosed initializer MUST be additionally enclosed in parentheses if it is used in constructor initialization list.<br />
219
-
Some valid use cases:
220
-
```c++
221
-
// aggregate
222
-
Person john = { "John", "Smith", 21 };
223
-
Person *john = new Person { "John", "Smith", 21 };
224
-
225
-
// array
226
-
int array[] = { 1, 2, 3, 4 };
227
-
228
-
// container
229
-
QHash<QString, QString> map = {
230
-
{ "key1", "value1" },
231
-
{ "key2", "value2" }
232
-
);
233
-
234
-
// member array
235
-
SomeClass::SomeClass(BaseClass *parent)
236
-
: BaseClass(parent)
237
-
, m_someArrayMember({ 1, 2, 3, 4 })
238
-
{
239
-
}
240
-
241
-
// return from function
242
-
Person getPersonByName(const QString &name)
243
-
{
244
-
// do something
245
-
return { name, surname, age };
246
-
}
247
-
248
-
// function argument
249
-
doSomething({ name, surname, age }, someOtherArg);
250
-
```
251
-
252
220
***auto** keyword
253
221
254
-
We allow the use of the **auto** keyword only where it doesn't break the readability of the code (i.e. either we can gather enough information about the type from the right part of the expression, or we do not need to know the exact type), or where it is strictly necessary (for example, to compute the type of a lambda, etc.).<br />
222
+
We allow the use of the **auto** keyword only where it is strictly necessary
223
+
(for example, to declare a lambda object, etc.), or where it **enhances** the readability of the code.
224
+
Declarations for which one can gather enough information about the object interface (type) from its name
225
+
or the usage pattern (an iterator or a loop variable are good examples of clear patterns)
226
+
or the right part of the expression nicely fit here.<br/>
227
+
<br/>
228
+
When weighing whether to use an auto-typed variable please think about potential reviewers of your code,
229
+
who will read it as a plain diff (on github.com, for instance). Please make sure that such reviewers can
230
+
understand the code completely and without excessive effort.<br/>
231
+
<br/>
255
232
Some valid use cases:
256
233
```c++
257
234
template <typename List>
@@ -274,9 +251,17 @@ auto spinBox = static_cast<QSpinBox*>(sender());
274
251
275
252
* Space around operations eg `a = b + c` or `a=b+c`:
276
253
277
-
Before and after the assignment there should be a space. One exception could be: for loops.
254
+
Before and after the assignment and other binary (and ternary) operators there should be a space.<br/>
255
+
There should not be a space between increment/decrement and its operand.<br/>
0 commit comments