Using namespace std
Seems like it was just yesterday when I was programming with some classmates and strangers at a project Euler sprint when the unknown happened. As we were working on the problem I quickly opened my text editor and begin typing out the boiler code. Type,type,tyep…type.
using namespace std;
WOHHH WOHH don’t do that!
What do you mean?
You are importing the entire namespace library.
At this point in my programming journey, I was somewhat new to C++ and only worked extensively with C thus it never crossed my mine when importing the entire stdlib library. I was simply programming without thinking how such an import could save us time when solving time constraint problems.
Why is using namespace std considered bad practice
After that particular meetup, I was intrigued by why such a statement was bad practice and dove deeper to broaden my understanding. Often times when programming we programmers tend to import or use libraries for tedious tasks.
What I found was when you declare
using namespace std you are importing the entire namespace library and given your experience you may only use a few of the provided functions declared in c++ standard library.
Use only what you need
Ever since that particular meetup I have written every program in such a way that I only import namespaces that are needed. This has also helped with readability and avoids naming collision especially when using c++ libraries such as boost which may have similar or the exact same namespaces as the standard library.