Consensus on the kdelibs coding style

Thiago Macieira thiago at
Sat Jul 5 19:37:22 BST 2008

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)

and then you add a large else condition, you have to make it:

    if (foo) {
    } else {
        // handle error condition

Which means you've just modified the 'if' line as well and no 
white-space-ignoring annotation will catch that.

Sometimes I wish we could write Perl-like code:

    bar() if (foo);

  Thiago Macieira  -  thiago (AT) - thiago (AT)
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <>

More information about the kde-core-devel mailing list