3 ms·
I think you should take a minute to think about it. Let me turn it around on you: Give me a simple example in code of something that is mutable and not state.
by jmull 2y ago
I think you should take a minute to think about it.
Let me turn it around on you: Give me a simple example in code of something that is mutable and not state.
I'll come back later to check your answer and provide one of my own, if necessary.
- jmull 2y agoOK, here it is: int addOne(int value) { value += 1; return value; } value is clearly mutable, yet not state. State is a value you can refer to later. Here, "value" doesn't outlive the function, so can't be referred to later. State is a complication because you have to worry about whether it remains up-to-date. (Mutable state is even more complex because you also have to worry about if/when it may be changed.)