4 ms·
What's actually more useful to get into is why you want to use immutable or mutable data in certain situations. If the data you have is not going to be written
by DannoHung 15y ago
What's actually more useful to get into is why you want to use immutable or mutable data in certain situations.
If the data you have is not going to be written to often (not never, mind) but will be shared widely, then it makes sense to use an immutable object (or structure) which will allow the shared aspects to vary locally, but minimize copying and redundant memory usage globally.
If you're going the other way, frequently written to and not shared widely, then mutable structures have advantages since mutation can be faster than partial reconstruction.
Not to say that this always holds true, but it's a decent rule of thumb and can help you make sane choices when initially selecting collections.