[Qt-creator] Coding style: Braces & single-line statements
Christian Kandeler
christian.kandeler at digia.com
Thu Sep 20 10:07:44 CEST 2012
Hi,
our coding style at
http://doc.qt.digia.com/qtcreator-extending/coding-style.html#braces
explicitly forbids curly braces around single-line conditional statements:
if (address.isEmpty()) { // Illegal braces
return false;
}
It also mandates curly braces in if/else constructs if at least one
block has them.
Now, consider this piece of code:
if (condition1) {
function1();
} else if (condition2) {
function2();
} else if ... {
...
} else if conditionx {
prepareStuff();
functionx();
}
The final else clause forces braces for all other conditional
statements. Now if I remove the call to prepareStuff, e.g. because it is
integrated into functionx, suddenly ALL the braces must go, because only
one-line statements are left.
In my experience, this kind of stuff happens a lot, and it's mighty
annoying both for the person who has to add/remove lots of braces for no
sensible reason and for the reviewer, who is distracted from the actual
content of the patch by all the noise.
I therefore propose that we stop disallowing braces for one-line
statements, instead leaving the decision to the discretion of the
respective developer.
Christian
More information about the Qt-creator
mailing list