+ 6

Why is "using namespace std;" still taught?

It's bad practice and it's unfortunate that so many beginners are learning something that will almost certainly bite them in the rear later on. SoloLearn should fix its C++ coursework.

10th May 2019, 2:10 AM
Matthew Elmer
17 Answers
+ 7
As this subject has been come up time and time again perhaps someone should create a user submitted lesson on the subject to properly explain namespaces and their usage.
10th May 2019, 2:43 AM
jay
jay - avatar
+ 7
You can have your cake and eat it too if you use `using namespace std`, but inside functions. int main(){ using namespace std; cout << ... } That way you're at least not clogging up the global namespace :P
10th May 2019, 3:40 PM
Schindlabua
Schindlabua - avatar
+ 6
Well I am no expert and I occasionally write some C++. I've always used 'using namespace std;' because no one until recently told me it's bad. I personally like the brief 'cout' syntax, a whole 2 characters shorter than even printf lol. I almost never use any other namespaces and therefore almost never have namespace clashes. Well that's just a personal opinion from a non expert.
10th May 2019, 10:53 AM
Sonic
Sonic - avatar
+ 6
Sonic, you can write ... using std::cout, std::cin; ... combining proper and lazy. ;-)
10th May 2019, 11:15 AM
HonFu
HonFu - avatar
+ 6
Oh you're good HonFu! 😉
10th May 2019, 11:49 AM
Sonic
Sonic - avatar
+ 6
Schindlabua the number of couts/cins within the function better be high to make that worthwhile 😂.
10th May 2019, 11:03 PM
Sonic
Sonic - avatar
+ 5
Maybe because for simpler codes where there is no risk of name space clash, it is useful in abbreviating the standard input/output stream names.
10th May 2019, 2:29 AM
Sonic
Sonic - avatar
+ 5
Wow this blew up. It warms my heart to see so many people that care :)
10th May 2019, 6:09 AM
Matthew Elmer
+ 4
That's true Jamie💐 . Matthew Elmer lol, yes.
10th May 2019, 2:32 AM
Sonic
Sonic - avatar
+ 2
So why should I trust SoloLearn if it does the same thing?!
10th May 2019, 2:15 AM
Matthew Elmer
+ 2
~ swim ~ there are so many things in the standard library that it's very easy to use functions and get unexpected results. Typing "std::" becomes automatic and it ensures you're getting the right function.
10th May 2019, 5:34 AM
Matthew Elmer
+ 2
~ swim ~ The fact that there may or may not be more C in the world is irrelevant. If someone wants to learn C++ they should be taught properly.
10th May 2019, 6:08 AM
Matthew Elmer
+ 2
I'm just starting to learn c++. I've had this app for A VERY long time, but I've always wanted to learn... any pointers?
10th May 2019, 6:28 AM
Junior Coby
Junior Coby - avatar
+ 1
Ah, best of luck to the beginners then, I hope they realize this
10th May 2019, 2:29 AM
Matthew Elmer
+ 1
I think it makes sense to teach everything, then improving the quality of code comes next, because it is a skill in itself. trying to say this and that is bad from the beginning is boring. for a beginner it's freaky to see std:: and long forms just to print a string. otherwise make it a rule in C++ to not use it, just like Python enforces indentation.
10th May 2019, 4:02 AM
Bahhaⵣ
Bahhaⵣ - avatar
- 3
Its true, just do it.
10th May 2019, 7:54 PM
abdullahi abdulazeez
abdullahi abdulazeez - avatar