No, and please do not do this.
The purpose of namespaces is primarily to resolve conflicts in the global namespace.
The secondary target is a local abbreviation of characters; for example, the sophisticated UpdateUI method may use using namespace WndUI to use shorter characters.
I am working on a 1.3MLoc project, and the only namespaces we have are:
- imported external COM libraries (mainly to isolate header conflicts between
#import and #include windows.h ) - One level of public API namespaces for certain aspects (user interface, database access, etc.).
- "Implementing details" of namespaces that are not part of the public API (anonymous namespaces in .cpp, or
ModuleDetailHereBeTygers namespaces in header-only) - transfers are the biggest problem in my experience. They pollute like crazy.
- I still feel that there are too many namespaces.
In this project, class names, etc. use two- or three-letter "regional" code (for example, CDBNode instead of DB::CNode ). If you prefer the latter, there is room for a second level of "public" namespaces, but nothing more.
Enumerations specific to a class, etc., can be members of these classes (although I agree that this is not always good, and it is sometimes difficult to say if you need to)
The company namespace is also rarely required, unless you have big problems with third-party libraries that are distributed as binary, do not provide your own namespace, and cannot easily be placed in one (for example, in a binary distribution). However, in my experience, getting them into the namespace is much easier.
[edit] According to the following Stegi question:
So, what about the Windows :: UI :: Xaml and Windows :: UI :: Xaml :: Controls :: Primitives namespaces in Win8 development? I think using the Microsoft namespace makes sense, and itโs really deeper than just 2 levels
Sorry if I was not clear enough: the two levels are not a hard limit, and are no longer internally bad. I just wanted to point out that you rarely need more than two, in my experience, even on a large code base. Investing deeper or finer is a compromise.
Now, Microsoft's case may be different. Presumably a much larger team, and all the code is a library.
I would suggest that Microsoft mimics the success of a .NET library, where namespaces contribute to the discovery of a vast library. (.NET has about 18,000 types.)
I would suggest that there are optimal (ordinal values) characters in the namespace. let's say 1 does not make sense, 100 sounds are right, 10,000 are clearly a lot.
TL; DR: This is a compromise, and we have no hard numbers. Play in a safe place, do not overdo it in any direction. โDonโt do thisโ comes simply from โYou have a problem with this, I would have a problem with this, and I see no reason why you need this.โ