+ 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.
17 Respuestas
+ 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.
+ 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
+ 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.
+ 6
Sonic, you can write ...
using std::cout, std::cin;
... combining proper and lazy. ;-)
+ 6
Oh you're good HonFu! 😉
+ 6
Schindlabua the number of couts/cins within the function better be high to make that worthwhile 😂.
+ 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.
+ 5
Wow this blew up. It warms my heart to see so many people that care :)
+ 4
yep and no, it teaches a new user about namespaces (or does it?)
anyway, here is some more reading on the subject
https://www.sololearn.com/discuss/294730/?ref=app
https://www.sololearn.com/discuss/187690/?ref=app
https://www.sololearn.com/discuss/1694246/?ref=app
https://www.sololearn.com/discuss/340041/?ref=app
https://www.sololearn.com/discuss/93433/?ref=app
+ 4
That's true Jamie💐 . Matthew Elmer lol, yes.
+ 2
So why should I trust SoloLearn if it does the same thing?!
+ 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.
+ 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.
+ 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?
+ 1
Ah, best of luck to the beginners then, I hope they realize this
+ 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.
- 3
Its true, just do it.