by AnimalMuppet · 6y ago · 0 comments
I have a Wallet with $500 in it. I call Wallet.pay(100). In your approach, it returns a new Wallet with $400 in it. But I also still have the old, unmutated Wallet with $500 in it, which could be referred to by mistake (or by malice). That's probably not the best argument for immutable objects...
I feel that objects offer a flexibility benefit though (which is why they often elude formal approaches) for the cost of purity.