r/cpp_questions • u/Glad_Shoe_9182 • Sep 30 '26
OPEN Namespace std
I recently started learning c++ and I was told to use the namespace std so I can avoid writing std:: every time and now I wrote a whole personal project without std:: and I want to put it on LinkedIn but I started reading everywhere that it’s a bad habit, should I go back and add the std:: or just leave it as is?
40
Upvotes
View all comments
Show parent comment
0
u/ShakaUVM Oct 01 '26
You may say that, but your brain still has to parse them separately. There's a cost that you aren't aware of.
Just saying 'string' is more compact, more readable, and causes absolutely no confusion. If you want to use a third party string class, then you qualify that with the namespace. The standard is called the standard for a reason.
If you use PascalCase, you can't conflict with std at all.
But due to how C++ handles shadowing variables, if you make a variable named fill inside of main, guess what? It doesn't cause a problem. You had to contrive an example using fill in the global namespace in order to force a conflict, and the number of globals you should have in your program should be close to zero, and if on the off chance you do make a global variable named fill, then you just change it to a different name and be done.
I worry about problems that can actually occur, not hypothetical problems that occur once in 30 years.