Re: namespaces, class libraries, and VERY large projects
werasm wrote:
Alan McKenney wrote:
Yes, what is your advice or comment on the OP's question (1,2 or 3 -
or
something not mentioned maybe?). It may be beneficial to him/us to
know, since you have such a vast amount of experience.
I'm afraid I can't contribute any experience with
the use of namespaces to partition projects.
Most of my experience has not been with C++.
My recent experience has been with C++, but I've not been
in a position to make these decisions, I've just had to live
with the consequences. Even when I have been in a position
to make such decisions, other programmers often do what they
feel like, anyway.
I've used namespaces in my pieces of projects, but have not
been able to get other people to do so. Actually, I've focused
more of my energy on things like standard-compliance,
const-correctness, extensibility, robustness, configurability,
and portability.
(I think most programmers tend to do whatever
will get their code written, compiled, and out the door quickest.)
OK, now that I've finished whining: I would go with explicitly
qualified names, with "using" statements for frequently used
names.
And your "using" statements should be in your .cpp files, not
in headers. You want don't want to have to be hunting through
a million .h files to find out where a name comes from.
Don't use "using namespace" statements. If the likelihood of name
collisions is high enough to require namespaces, then you'll have
to get rid of them, anyway, and adding qualifiers everywhere in
a million lines of code after you've written, debugged, and forgotten
them is a *lot* harder than doing it right the first time.
(A general rule: do your best to write code you won't have to revisit.
The cost of changing one line of code goes up both as time
passes and as the amount of code that depends upon it goes up.)
I don't even use "using namespace std" or "using std::string" or
"using std::cout" statements. It makes it easer to find them
with search commands.
I don't have a lot of experience with nested namespaces. My
experience with nested classes has run into enough annoying
restrictions that I would not use nested namespaces on a big
project until I had a fair amount of experiences on projects small
enough that un-nesting them later on wouldn't be a big problem.
-- Alan McKenney
[line eater fodder]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]