Re:It's not what programming languages do, it's what they sh...
by nottorp on Friday March 27, 2020 @04:21AM
(#22701189)
> It's much more manageable to have a game class object, where inside it, what used to be global could now just a private member that's global to that class.
That's still a global, except now it has lipstick.
Re:It's not what programming languages do, it's what they sh...
by mastrsushi on Friday March 27, 2020 @09:54AM
(#22702815)
If it's private in the class then why are you saying it's global?
Re:It's not what programming languages do, it's what they sh...
by nottorp on Friday March 27, 2020 @11:13AM
(#22703469)
"a game class object" is 99.95% likely to contain the whole game. Doesn't matter that it's labeled private, it's basically global to all the code of the ... game.
Re:It's not what programming languages do, it's what they sh...
by mastrsushi on Friday March 27, 2020 @11:45AM
(#22703851)
> 99.95% likely to contain the whole game
That doesn't sound like a wise assumption. It is common to have the actual engine of the game, and even the game itself separate from other architectural components.
A big problem with global is that it's often abused as a work around. Restricting access is an abstraction. The user isn't expected to alter this value, why should they be allowed to? What's more critical is the fact that the programmer might not realize what they wanted to be simply accessible is in fact static as well. So you now have a variable that's not only accessible, but state dependent. Now anyone using this variable has to be mindful of this.
Unless there is C code being called as well, in C++ you should rarely use global. It's much more manageable to have a game class object, where inside it, what used to be global could now just a private member that's global to that class.
You're team put in all that effort to remove global because it takes even more effort to get rid of all the trivial errors tied to the choice to begin with.
It all comes down to writing reusable code, objects that manage themselves. People shouldn't have to be cautious when reusing code. This doesnt only apply to other programmers but yourself 6 months down the line.