[Development] Namespaces (was: Qt Platform Extras)

Thiago Macieira thiago.macieira at intel.com
Tue Sep 17 15:38:13 CEST 2013


On terça-feira, 17 de setembro de 2013 18:30:32, Sze Howe Koh wrote:
> > I think I agree with JP. AFAICS, no other module is using module-wide
> > namespaces, so it would not be inconsistent to name it QtFoo.
> Actually, there are 5 such module-namespace pairs:
>     * Qt D-Bus -- QDBus
>     * Qt Multimedia -- QMultimedia
>     * Qt OpenGL -- QGL
>     * Qt SQL -- QSql
>     * Qt Test -- QTest
> 
> The odd one out is:
>     * Qt Concurrent -- QtConcurrent

Of those 5 you listed, only QtTest / QTest is a module-wide namespace. The 
QDBus module contains just a couple of constants, just like QSql. The classes 
themselves are not inside the namespace and there are no functions inside the 
namespace either.

QtConcurrent, on the other hand, is a very good example of a module-wide 
namespace.

> > Also, using QtFoo makes it consistent with the module-wide include:
> > #include <QtFoo>
> > 
> > (And it cannot be #include <QFoo> since that would be inconsistent with
> > our other module-wide includes)
> The headers for the namespaces listed above are:
>     #include <QDBus>

Doesn't exist.

>     #include <QMultimedia>

Just a few constants, not equivalent to <QtMultimedia>

>     #include <QGL>

Doesn't exist.

>     #include <QSql>

Just four enums, no classes, not equivalent to <QtSql>.

>     #include <QTest>

This is the only one that is equivalent to <QtTest>.

> 
> ...and:
>     #include <QtConcurrentMap>, #include <QtConcurrentFilter>,
> #include <QtConcurrentRun>
> (The QtConcurrent namespace is split across different headers)

None of those includes are official.

> These namespace includes are NOT the same as module-wide includes. I
> think module-wide includes should only ever be used for rapid
> prototyping. We should make it possible to use a namespaced function
> without pulling in every other class in the module.
> 
> Example:
> #include <QMultimedia> pulls in the QMultimedia namespace only, but
> #include <QtMultimedia> pulls in the QMultimedia namespace PLUS all
> the audio, video, radio, camera etc. classes. This can adversely
> impact compilation times for large projects.
> 
> If we want to start using QtFoo namespaces, I think we should also
> decide on a new (and universally-applicable) header scheme. Maybe
> #include <QtFooNamespace>?

That is a very good point. If the namespace name is the same as the module 
name, then you can only include the entire module if you try to get the 
namespace.

The question is: is that so bad? I don't think so. If such a module grows, you 
can always include the individual classes instead of the module-wide include.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130917/c8460697/attachment.sig>


More information about the Development mailing list