• 0 Posts
  • 2 Comments
Joined 2 years ago
cake
Cake day: July 1st, 2023

help-circle
  • Well, but then you’re basically just pushing the mutability onto the container

    That’s the point, when programming with immutable structures you always pass the mutability onto the enclosing structure.

    It’s a good strategy at times though. Like say you’re working in a language where strings are immutable and you want a string you can change. You can wrap it in a list along the lines s=['foo'] and pass references to the list around instead. Then if you go s[0]='bar' at some point, all the references will now see ['bar'] instead.

    A list is an antipattern here IMO. Just wrap it in some dedicated object (see e.g. Java’s StringBuilder).