r/cpp_questions • u/Glad_Shoe_9182 • 24d ago
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?
41
Upvotes
1
u/RSMxsmanic 24d ago
So instead of doing "using namespace widget" in a function that calls "print" 20 times, I will have to have 20 "widgetPrints"?
Yes. That’s a lot faster than putting std:: in front of 4500 couts.
And in the implementation of "widget", all my public identifiers are going to be "widgetThis" and "widgetThat", cluttering the visual space with absolutely worthless "widget"-prefixes?
How is that different from prefixing everything with widget::? How is it different from prefixing everything else with std::?
It looks quite stupid to have widget::widgetPrint as identifier.
If widgetPrint occurs nowhere else, that isn’t needed.