I really enjoyed this video and learned a lot about mutation. Thank you for making it!
I have a few questions:
- When is it appropriate to mutate an object?
- When is it encouraged to mutate an object? Are there examples?
I think in the video I heard it was appropriate to mutate objects when the object’s state is local to the function of the class. In other words, if the object is neither passed in as an argument or a collaborator to the class, then it is permitted to mutate an object because the side effects of the change to the object are arguably minimal – there is not a disastrous ripple effect of change across your application.
Still, I did not hear a the speakers talk about examples where it is encouraged to mutate an object vs creating a new one in memory. There seemed to be a strict preference for pure functions.