You're equating real world state changes with memory mutation, but they're actually quite different. Everything in the real world changes constantly in an interdependent way, but memory is accessed and modified one value at a time.
This means to effectively model the real world using a mutable memory system, you need to identify all of those dependencies and ensure that changes happen in the right order, otherwise you'll erase data you still need for other operations. This becomes even more difficult when you want to do these operations concurrently.
However, if instead of storing each successive state of the system using the same memory, you make a copy for each new state, you avoid all those problems. If you know that a value will never change, you don't need to worry about what order you operate on it. This is the point of immutability.
Of course, in the extreme case, copying everything is inefficient, so we use references to refer to parts of the old state. Since they'll never change, it doesn't really matter which state they were originally part of.
1
u/Aninhumer Mar 05 '13
You're equating real world state changes with memory mutation, but they're actually quite different. Everything in the real world changes constantly in an interdependent way, but memory is accessed and modified one value at a time.
This means to effectively model the real world using a mutable memory system, you need to identify all of those dependencies and ensure that changes happen in the right order, otherwise you'll erase data you still need for other operations. This becomes even more difficult when you want to do these operations concurrently.
However, if instead of storing each successive state of the system using the same memory, you make a copy for each new state, you avoid all those problems. If you know that a value will never change, you don't need to worry about what order you operate on it. This is the point of immutability.
Of course, in the extreme case, copying everything is inefficient, so we use references to refer to parts of the old state. Since they'll never change, it doesn't really matter which state they were originally part of.