Re: should "using namespace std" be used?
"Cy Edmunds" <spamless.cedmunds@rochester.rr.com> wrote:
"Daniel T." <daniel_t@earthlink.net> wrote:
"Cy Edmunds" <spamless.cedmunds@rochester.rr.com> wrote:
[snip]
In effect, namespaces allow us to put warts on all the standard
library names which, given their sheer number, seems like a damned
good idea to me.
[snip]
Now I understand the disconnect: we have radically different ideas about
the
purpose of namespaces.
So you think the reason the namespace mechanism was introduced is so
that the standard library names would have warts?
Of course! It does other useful things, too, all of which have to do with
*adding* warts. It certainly does nothing to remove warts. Consider:
Old way:
#include <iostream.h>
cout << 44;
My way:
#include <iostream>
std::cout << 44; // now we have warts
Your way:
#include <iosteam>
using namespace std;
cout << 44; // same warts (none) as old way
So the net effect of namespaces is to introduce new warts although the using
clause gives us a way to sort of break even with some extra effort.
In spite of the unattractive name, I think warts are useful for avoiding
name conflicts as the code evolves.
"As the code evolves" makes it sound like some huge bug-a-boo that you
are somehow magically avoiding by putting "std::" in front of a good
chunk of the code in a cpp file.
This name conflict issue that you are so concerned about, that you add
an extra five plus characters to every reference of every type in your
code is a chimera. The rare instance when it comes up, the compiler
invariably points it out, and is easy to fix. The problem simply doesn't
exist.