nateshmbhat / snakes

A LAN Multiplayer Snake game in C++ . This is a snake game which is a console based game written in C++ to which any number of players in LAN can join and play with their corresponding snakes with smooth synchronization.
MIT License
15 stars 2 forks source link

Small Changes #1

Closed ThomasThelen closed 5 years ago

ThomasThelen commented 6 years ago

Take out `using namsepsace std`

See https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice

Get Rid of the Global Variables

You should never have global variables in your program. The colors can be defined in an enum. But be sure to use a scoped enum. The class declarations can be put in the main function. If you need them in a function, pass it by reference.

Take String Arguments by const ref When Possible

Game::printAnimated(string msg , int speed) can be written as Game::printAnimated(const string& msg , int speed)

In the first way, the compiler copies the value that you passed to the function into msg. Since you don't actually modify msg at all, there's no point in having a copy of it. The second way passes the memory address of the string, so it avoids expensive memory allocations. This can be done in a few other functions.

Use the auto keyword

http://www.learncpp.com/cpp-tutorial/4-8-the-auto-keyword/

nateshmbhat commented 6 years ago

Thanks so much for posting this :)