[Development] kdelibs coding style

Samuel Rødal samuel.rodal at digia.com
Tue Apr 30 08:54:31 CEST 2013


On 04/29/2013 10:31 PM, Olivier Goffart wrote:
> On Monday 29 April 2013 09:43:55 Thiago Macieira wrote:
>> On segunda-feira, 29 de abril de 2013 17.16.49, Sergio Martins wrote:
>>> The thing is, I just discovered that the kdelibs style[1] has a little
>>> difference from Qt, it uses braces for one-line if statements.
>>>
>>> This seems to be a documentation/policy only rule, as the kdelibs code is
>>> full of if's without braces.
>>
>> Remember that kdelibs isn't completely ported over to the kdelibs coding
>> style.
>>
>> So you may be seeing code that simply needs to be fixed when it's next
>> touched.
>>
>> The brace-on-one-line-if was adopted for KDE for a couple of good reasons:
>>
>> 1) when you add a second line, the if line does not need to be changed
>> 2) conversely, if the if had a second line and you remove it, you don't need
>> to change the if
>> 3) you're less likely to make this mistake:
>> 	if (condition);
>> 		doThat();
>>
>> The reason Qt requests that the braces not be added is a simple one:
>> 1) it's uglier
>>
>> With that in mind, I would suggest we change *both* coding styles to
>> optionally permit the braces, and strongly suggest it for more-complex
>> conditionals. In particular, it should suggest you leave the braces if
>> you've reduced the statements to one line.
>
> I support the change to optionally permit the braces.

+1

A good reason for using the

Foo()
     : x(0)
     , y(0)
{
}

syntax for initializer lists after all is to make diffs easier to read 
when adding or removing a member variable. The same argument could be 
made for permitting braces for one-line if-statements.

--
Samuel




More information about the Development mailing list