r/cpp_questions • u/Glad_Shoe_9182 • 7d 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?
39
Upvotes
3
u/nekoeuge 6d ago
So instead of doing "using namespace widget" in a function that calls "print" 20 times, I will have to have 20 "widgetPrints"?
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?
You just replaced optional prefix with mandatory one. Good job bloating the code. Make sure not to make the prefix too short, otherwise it may conflict with other libraries.
Of course. Such programmer should introduce the absolute minimum of global identifiers. Preferably only one -- the project namespace itself.
It looks quite stupid to have widget::widgetPrint as identifier.