|
|
|
|
|
by zrobotics
2578 days ago
|
|
Definitely very true. I write more C++ than anything else, and the sheer number of online examples that start with using namespace std;
is just staggering. Sure, it works in a toy example posted to stackoverflow, but it will cause problems in larger projects. I think globally there needs to be better emphasis on using best-practices in tutorials and examples; I remember this particular pet-peeve of mine also being present in college textbooks. Especially for content aimed at newbies, it should be frowned upon to show the wrong way to do things, since then it gets harder to show how to do it the right way.
I've had people who were surprised to find out that they could type: using std::chrono::duration;
using std::cout;
instead of pulling in the entire std namespace; simply because they'd only ever seen examples that did it the lazy way.edit: lack of semicolons strikes again! |
|
> sometimes a namespace is so fundamental and prevalent in a code base, that consistent qualification would be verbose and distracting.
I also work mainly in C++, and personally I prefer using it, together with -Wshadow to catch possible issues.
0: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC...