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

  • Kacarott@aussie.zone
    link
    fedilink
    arrow-up
    5
    ·
    13 hours ago

    This is close, but as someone already said, an index into a list just means you are mutating the list.

    Your stable “identifier” needs to be a function, ie. a reused design pattern. Compared to the list, this would be an index function which gets an element from an arbitrary list, meaning you don’t have to mutate your list anymore, you just build a new one which still works with your function.

    This is why languages which avoid mutation and side effects are always (to my knowledge) functional languages.