|
|
|
|
|
by tooltower
1999 days ago
|
|
To avoid race conditions and to preserve abstraction boundaries. This is the archetypical design pattern in functional languages. For a simple example, if you first check the size of a vector before accessing index `i`, you can be sure the length hasn't changed right after your size-check. It's exactly like writing code only using only immutable Strings of Java, or frozen sets of Python. So in your example, it "continues to exist" in local variables to reflect the state of the system as it was when you read it, as long as you still hold a reference to the old vector. Typically, you'd ask your software to fetch a fresh copy of the vector any time you'd want new data. But that's explicit in code. You'll have fewer surprises if mutation (like vector-appends) are never shared between variables. |
|