Search code examples
c++iostreamiomanip

Why are these C++ Commands looked down upon?


I know many people have suggested to me to not use code such as

using namespace std;

or

system ("pause");
system ("cls");
system ("color f0");//and other system commands

or

goto TitleScreen;
goto DeathScreen;

or

break;

and I'm just wondering why these things are looked down upon and what C++ commands can replace the bad habits of mine?


Solution

  • Okay, let's go one-by-one. I will be posting links to great post by some other people, there's no points reinventing the wheel, and they've done a pretty good job.

    using namespace std;
    

    Why is "using namespace std" considered bad practice?

    system ("pause");
    system ("cls");
    system ("color f0");//and other system commands
    

    Why system() is evil

    break;
    

    There's nothing necessarily bad about break if used in moderation. Too many breaks in a for loop might suggest your logic is getting a bit too complex, and may be factored out, but in general most 'dangers' with break and continue can be alleviated by writing clear code.