4 ms·
I agree. But here's the problem I have. If we don't want people to use global variables, the advice should be 'don't use global variables'. There is no need to
by sago 9y ago
I agree.
But here's the problem I have. If we don't want people to use global variables, the advice should be 'don't use global variables'. There is no need to wrap it up in 'avoid global mutable state', when using global mutable state is unavoidable in many cases and the best engineering solution in many others.
At the point you have to nuance it to 'reduce your code's exposure use global mutable state, accessing it through mockable interfaces, and defensively checking its values' to mean 'don't use global variables', it may be simpler to say what we mean.
For example: there is a comment lower down in this thread of someone confused by the advice in the context of the game engine. I've worked with hundreds of game engines, every one of them has global mutable state.
- otakucode 9y agoIn many languages, variables are not necessarily state. Global variables are fine if they're global constants which can not (not just 'should not') be modified.