[Development] Header file cleanups

Mathias Hasselmann mathias at openismus.com
Thu Mar 1 12:44:47 CET 2012


Am Donnerstag, den 01.03.2012, 11:27 +0000 schrieb lars.knoll at nokia.com:
> On 3/1/12 11:02 AM, "ext Thiago Macieira" <thiago.macieira at intel.com>
> wrote:
> 
> >On quinta-feira, 1 de março de 2012 08.22.42, lars.knoll at nokia.com wrote:
> >> Hi,
> >> 
> >> I've seen a few examples where people are cleaning up includes in header
> >> (public or private but exported to other modules) files, as e.g.
> >> http://codereview.qt-project.org/#change,18095.
> >> 
> >> While they are correct in theory, they cause problems in practice and
> >> provide close to 0 (in fact negative) value to Qt. The only advantage is
> >> some purity of our code and maybe a .1% speedup of compilation. This
> >>does
> >> not outweigh the negative side effects:
> >> 
> >> * They break SC needlessly for people porting from Qt 4.x
> >> * They break downstream projects and some people (including myself) are
> >> wasting quite a bit of time fixing up these breakages instead of fixing
> >> actual bugs.
> >> 
> >> So please *don't* do these changes. They are simply not worth it.
> >
> >In the interest of getting work done and getting a 5.0 release, I'll
> >agree 
> >with Lars. Let's not do those potentially-incompatible changes right now.
> >
> >But I'd say that they can be done in the future. Depending on indirect
> >includes is a bug in the user code, in my book.
> 
> According to the book it is. But in practice it happens all the time, and
> we know it.

To which book? C++ compilers and IDEs give zero support in enforcing
direct includes. Considering the mess GNU libc headers are, I even
wonder how to formulate automatic checks for direct includes.

Considering this weakness of C and C++ some have come to the conclusion
that indirect includes are part of the API. Removing redundant include
directives from released headers actually is an API break in C/C++.

> Qt is first and foremost about making developers life easy, purity of code
> comes second.

The GNOME guys went the pragmatic approach and now forbid direct
includes. You always must include the module headers for GTK+ and
friends now (unless explicitly asking for trouble):

        #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
        #error "Only <gtk/gtk.h> can be included directly."
        #endif
        
Sadly, considering the slowness of g++ and the complexity of Qt, I doubt
this is a reasonable approach for Qt.

Ciao,
Mathias




More information about the Development mailing list