It makes the code icky and hard to debug, and you can simply return new immutable objects for every state change.

EDIT: why not just create a new object and reassign variable to point to the new object

  • wewbull@feddit.uk
    link
    fedilink
    English
    arrow-up
    7
    ·
    5 days ago

    You can do exactly as you say, and you’re right - it makes code easier to reason about. However it all come down to efficiency. Copying a large data structure to modify one element in it is slow. So we deal with the ick of mutable data to preserve performance.