|Wouldn't it be better to just introduce students to something like using std::cout; instead of the global namespace? Forgive my ignorance, but is declaring a form of using globally bad in general? |
The trouble with that is that it's not too hard to have lots of those at the beginning of a file, so it becomes a pain. Imagine needing various containers and algorithms, I have had up to 14 using statements in the past, so I don't do that anymore. But they are not a bad thing per se.
If someone sends me code that has std:: throughout, then I don't have to do anything to it.
The other thing about specifying
is that it says which of something one is using:
or some other
from a library somewhere.
Speaking of boost, it's seems to be ok to have
if the namespace is small, boost do this all the time in their code examples. I have found that to be a pain also.
Stroustrup himself also has
using namespace std;
, one would think if there was anyone who had an interest in doing things "correctly
" , it would be him. Perhaps he feels it is OK for small pieces of student code.
Ideally one should put their own code in their own namespaces.