As you can see, mutable objects seem more flexible and give us good performance. But if that's the case, then why wouldn't we want everything to be mutable by default? There are a couple of reasons:
- Immutable objects are easier to handle. Because the data in the object is fixed and never changes, a function that operates on these objects will always return consistent results. That is a very nice property to have because there are no surprises. And if we build a function that caches calculation results from such objects, the cache will always be good and return consistent results.
- Mutable objects are more difficult to work with in a multi-threaded application. Let's say that a function is reading from a mutable object, ...