2 ms·
> I'm saying that if you don't have functional code throughout, you might end up copying more often than you think. Immutability means you can hang on to things
by _bxg1 7y ago
> I'm saying that if you don't have functional code throughout, you might end up copying more often than you think. Immutability means you can hang on to things and share them with confidence.
But if you need to copy you're still following an "immutable" pattern: needing to share data with the guarantee that it won't be changed. Copying is just a very blunt way of accomplishing that. Immutable data structures will of course be a big improvement over simple copying whenever you need to do this sort of thing, but if you can avoid it altogether by modifying things in place instead of relying on their lack of mutation, you'll have even less overhead.
Clojure's transients, for example, were created for exactly this purpose: https://clojure.org/reference/transients https://clojure.org/reference/transients