Consensus on the kdelibs coding style

David Jarvie djarvie at
Sat Jul 5 21:01:29 BST 2008

On Sat 5 July 2008 19:37:22 Thiago Macieira wrote:
> Cornelius Schumacher wrote:
> >- When you have if blocks with one-liners which don't have brackets, it
> > can in some cases lead to wrong code, if somebody adds an indented line
> > of code, but no brackets. It looks right, but us wrong. Additionally
> > when moving around code, you might end with dangling brackets, if some
> > code blocks use them and some others don't.
> There's a technical reason for that too.
> The original Qt style says: you don't put brackets around simple lines,
> but you should if it's more than one line (including comments) and you
> bracket everything if any of the branches has it.
> So, if you have the code:
>     if (foo)
>         bar();
> and then you add a large else condition, you have to make it:
>     if (foo) {
>         bar();
>     } else {
>         // handle error condition
>         baz();
>     }
> Which means you've just modified the 'if' line as well and no
> white-space-ignoring annotation will catch that.

Of course, using aligned brackets instead of trailing ones solves this 
particular issue.

David Jarvie.
KAlarm author and maintainer.

More information about the kde-core-devel mailing list