using namespace std reasons for avoing

I know fundamentally that declaring using namespace std is generally considered bad form, and i get that it is to do with personnel namespaces, but can anyone explain it better then that? Why, as a new programmer, would I not want to save time by writing one line of code instead of putting std:: in front of 80% of my code?
Because it builds a bad habit, and habits are hard to break. Build good habits, not bad habits.
Okay, i get that can you clarify what is bad about the habit?
http://www.gotw.ca/publications/migrating_to_namespaces.htm
http://www.gotw.ca/publications/mill02.htm

The problem with the dark side / bad habits / addictive substances is that while they seem easy, nice and tempting, they are very hard to get rid off. The time you would "save" now is nothing compared to the anguish of debugging silent ambiguities that the use of directive can lead to.
Last edited on
closed account (z05DSL3A)
using Declarations, ie:

1
2
3
using std::cout;
using std::cin;
using std::endl


add names to the scope in which they are declared. The effect of this is:
» a compilation error occurs if the same name is declared elsewhere in the same scope;
» if the same name is declared in an enclosing scope, the name in the namespace hides it.

The using directive, ie using namespace std;, does not add a name to the current scope, it only makes the names accesable from it. This means that:
» If a name is declared within a local scope it hides the name from the namespace;
» a name in a namespace hides the same name from an enclosing scope;
» a compilation error occurs if the same name is made visible from multiple namespaces or a name is made visible that hides a name in the global name space.
Last edited on
if the same name is declared in an enclosing scope, the name in the namespace hides it.
Also I must add that other unqualified lookup rules still apply. For example ADL still works (and using declarations are often used with ADL).
Topic archived. No new replies allowed.