In C++, when you see a name in a source file, it is *very* difficult to
determine which namespace it lives under. My normal workflow is something
like: look for the name declaration, continue looking upward in the source
file for namespace declarations, and figure out the fully qualified name,
and then reference the symbol using the required namespaces. This is very
painful in practice and frequently causes unneeded recompilation cycles for
me when I start to touch parts of the code base which I'm not quite
familiar with.
This is an argument against using too many namespaces. Things get worse if
you use nested namespaces too much (see the workflow above).
So, if we were back at the drawing board today and were trying to figure
out how to use namespaces, here's what I would suggest:
1. Put our own code (sans things like NSS and NSPR) under namespace mozilla
(hmm, well, with the JS engine being the obvious exception :/ ).
2. Do not allow any other namespace at the global scope for our own code.
3. For the few exceptional cases where name clashes can actually occur
conceivably, use namespaces denoting the module name all in lower case
nested *only* one level under ::mozilla.
For example, under this set of rules, mozilla::gfx::Path sounds like a
reasonable name (as the Path name could conceivably be used by other
modules, however, mozilla::gfx::SkiaPath does not make any sense, and
should be changed to mozilla::SkiaPath.
If we were to adhere to these rules, we would gain two important benefits:
very little confusion on where names come from (all of our code would be
under namespace mozilla) and very little confusion on where names should go
(under mozilla::, unless you can justfiy why the name in question is so
common which demands living under mozilla::<module_name>).
One possible objection to this proposal would be different teams wanting
different namespaces for their own code. I personally tend to think that
tendency would lead to duplicating information which is already quite
evident in our code (like, if your file lives under the gfx/ directory,
it's part of the Graphics module.)
I'd be interested to hear people's thoughts on this.
Cheers,
--
Ehsan
<
http://ehsanakhgari.org/>
> ______________________________**_________________
> dev-platform mailing list
>
dev-pl...@lists.mozilla.org
>
https://lists.mozilla.org/**listinfo/dev-platform<
https://lists.mozilla.org/listinfo/dev-platform>
>