[Development] Can we remove recommendation against unnamed namespaces from Qt coding conventions?

Edward Welbourne edward.welbourne at qt.io
Wed Feb 21 19:56:49 CET 2024


Andre' Poenitz <apoenitz at t-online.de> (21 February 2024 19:21) wrote:
> 1. 'static' is attached to individual functions, not a scope of
> uncertain extend. When working on unfamiliar code it helps to
> understand the context. With 'static' the locality is obvious in the
> immediate context of the function and not set by some 'namespace {'
> potentiall a dozen functions and hundreds of lines of code away.

In particular this means that if someone picks up the function and moves
it elsewhere in the file, cut and paste, it's very easy to fail to
notice that they've moved it out of a nameless namespace and thereby
suddenly made it visible to the linker.  They'd have taken that little
word "static" on the front of the declaration with it, if it'd been
there, because it's not so easy to miss.

(Incidentally, the ways I can think of to say "has no name" tend to
suffer from some degree of precedent as "has a name but it has not been
disclosed" - the anonymous author of a pamphlet, the unnamed person who
reported a problem.  I'm currently unable to think of such a precedent
for "nameless", but I suspect that's only that I can't currently think
of it.  Then again, if a namespace with no name actually does have a
secret name, I guess that just matches the linguistic baggage.)

	Eddy.


More information about the Development mailing list