[Development] kdelibs coding style

Olivier Goffart olivier at woboq.com
Mon Apr 29 22:31:33 CEST 2013


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.

-- 
Olivier 

Woboq - Qt services and support - http://woboq.com - http://code.woboq.org



More information about the Development mailing list