[Development] Qt Coding Guidelines

Jędrzej Nowacki jedrzej.nowacki at theqtcompany.com
Fri Mar 18 08:48:52 CET 2016

On Thursday 17 of March 2016 12:29:46 André Somers wrote:
> Op 17/03/2016 om 11:24 schreef Mathias Hasselmann:
> > Am 17.03.2016 um 10:01 schrieb Sorvig Morten:
> >> How about treating the coding guidelines as \internal documentation?
> >> We could then at some point build and publish it together with the
> >> rest of the \internal's. (suitably separated from the public user
> >> documentation)
> > 
> > Actually having the Qt code style as public document proved to be
> > extremely useful in the past to quickly shutdown this inevitable and
> > highly annoying bike shed discussion about code style that happens at
> > the start of every other project. Also in the future I'd like to say:
> > 
> > "We do a Qt based project and for consistency I propose to follow the
> > Qt code style: It's a good and proven style guide. Just read it
> > http://wiki.qt.io/Coding_Conventions and then focus on real problems."
> I actually prefer to just delegate the actual formatting style to clang
> format now and apply that automagically. Perhaps it is not perfect in
> everyones eyes, but it is better that having differences all over the
> place or wasting time on discussing tabs, spaces or the location of * or
> &. But that's layout mostly, and there is a lot more to say than that
> (naming conventions, patterns to use or avoid, etc.) You still have to
> decide on what format to use, but the default is fine by me. So in any
> style guide, I'd probably not waste any more time on the formatting
> aspects any more, and just refer to something like "we use clang format
> with the LLVM style" or something like that.
> André


Every time someone discuss coding style issues my blood boils. I understand 
that it is important to have consistent coding style, but discussing where to 
put braces or spaces is just waste of developing time.

I'm totally for an automated solution. I would even say that every rule 
formatting related which is not expressed in some tooling aware code should 
disappear. In addition, I really do not like that sanity bot is complaining 
about typos after I pushed patches to gerrit and even worse it is commenting 
on my code instead of proposing a fix. 

As you said coding convention are a bit bigger topic, but it also should be 
automated. Seriously, rules about where to place Q_DECLARE_METATYPE or a check 
if an include is missing are quite easy to express.

So I think, that we should not discuss what is better qdoc or md. The real 
discussion is about tooling, what is the best tool to sanitize Qt code. We 
need something that:
1. Can work as a sanity bot
2. Can re-format the code by applying changes (git hook?)
3. Rules are easy to express and they can be exported (qdoc, html, fooBar)
4. Works on diff level (so it doesn't complain about the whole world being 

5. C++, js, qml awareness


More information about the Development mailing list