3 ms·
Yes but with persistent data structures each operation implies a cost, more or less big. For example most of times you do something with an persistent array you
by jfet97 8y ago
Yes but with persistent data structures each operation implies a cost, more or less big. For example most of times you do something with an persistent array you end up with fully cloning it.
What's the point? I know the advantages of immutability, but I think that perform impure operations into pure functions, in a safe contest, is not so bad.
My function can help with this...we could perform those faster impure operations (modifiyng local objects and arrays) and then create full, deeply cloned entities to pass around.
- yogthos 8y agoSo my day job is working with Clojure/Script that defaults to immutability, and my team builds fairly large apps, here's a talk describing one of them https://www.youtube.com/watch?v=aXBe6hoi-Mw https://www.youtube.com/watch?v=aXBe6hoi-Mw In almost a decade of using Clojure, I've never seen persistent data structures become the bottleneck. The difference in cost is O(1) for in place mutation vs O(log 32 n) for revisioning. Note that the large exponent means the tree ends up being very flat, so updates end up being quite cheap in practice. Most times when I do something to a persistent data structure, I only change a small portion of the overall data structure. In fact, I think it's quite rare that you'd end up cloning the whole thing. Personally, I view mutability as an optimization, and I think it should be used in cases where you actually need the performance beyond what persistent data structures can offer. My experience is that such cases are far and few between.