|
|
|
|
|
by lmm
1963 days ago
|
|
> By that logic all state in any program is global. All state in any program is global in the sense of being reachable from top-level. You can, and should, make your state hierarchical - reachable from top-level should not mean reachable from anywhere, you can have (non-toplevel) parts of your program that only access parts of your state. Unfortunately OO is uniquely bad at this, because objects are encouraged to have hidden coupling. > But if I'm writing an MMO server my GoldCoin class doesn't need to know about the client's connection state. But you have no way of knowing or enforcing that. "You wanted a banana but what you got was a gorilla holding the banana and the entire jungle" - your GoldCoin might contain a ("encapsulated" i.e. hidden) reference to another class that has a reference to another class and so on, and so eventually it does depend on the client's connection state. > Have you actually written or worked with OO code before? Yes, for many years, which is why I've become an advocate of FP style instead. |
|
Well, think about a random number generator. It has some internal state, which gets set by some action taken (perhaps indirectly) by the top level. And that state is "reachable" by getting the next random number, but that random number may not be a direct representation of any part of the generator's state. Also, after initialization, the generator's state should not be alterable by the rest of the program.
So to me, that's not really "reachable". The entire point of encapulating that state in the random number generator is to make it not reachable.