Hello, everyone! These days i was told that is not good to use using namespace std and that i should put std:: in front of every std function( like cout, cin, etc). I am asking you, real programmers why should i do this.. if you can explain in large amounts please!
Thanks in advance!
The using directive, ie: usingnamespace 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.
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 the name in the namespace hides it.
so, from what i understand , this would not be a problem for my begginer/intermediate programs but it will become when i will start real programming. Am i right?
> this would not be a problem for my begginer/intermediate programs
> but it will become when i will start real programming. Am i right?
Right.
A good programmer is, to a large extent, a programmer who has developed good programming habits; one who cares about programming hygiene.
The problem with inculcating early bad habits is that, in practice, it is exceedingly difficult to get rid of them later. Far easier to start doing things right from the very outset.