(no title)
siempreb | 6 years ago
If this construct, that I actually never needed in my entire career, is handy for undo/redo, why not just have a dead simple undo stack? In what situation is an immutable structure your best choice?
siempreb | 6 years ago
If this construct, that I actually never needed in my entire career, is handy for undo/redo, why not just have a dead simple undo stack? In what situation is an immutable structure your best choice?
maemre|6 years ago
The algorithms used in these analyses are usually described in terms of mathematical objects which are inherently immutable and using immutable objects makes correctness proofs easier.
When writing a piece of code, I start with immutable data structures because of the ease of mind they bring to the table (you can pass them around and you know they will not be modified so it makes reasoning and debugging easier, this is less of a problem in C++ because it has const references and const methods). Then, if an algorithm needs a mutable data structure or if the immutable data structures are too slow (e.g. the code is in the hot path) then I switch to mutable data structures. I think it is just a different mentality when approaching programming. It works for me because (a) it is the norm in my field (program analysis, or programming languages in general), and (b) I use a programming language with an ecosystem around immutable data structures (Scala).
siempreb|6 years ago
hokkos|6 years ago
This is extremely useful for undo/redo, it basically comes for free with it. You no longer have to deal with invisible mutation, listener, event, you just generate the ui on each change from the base to the leaf, and everything is always correct for free. The advantage over an undo stack is that there is a re-utilization of unchanged intermediate data structure (what is change is only the path from the base to the changed element), so you can add a simple ref check in the ui to not redraw of the underlying data has not changed. So the perf come for free.
dfgdghdf|6 years ago
In the OOP world, you might have a "getter" for a property (e.g. a list of some kind) that you don't want readers to be able to modify.
Perhaps "set" was a poor name here, since it usually means something else in a C++ context. I quite like "with".
dfgdghdf|6 years ago
physicsyogi|6 years ago
bjoli|6 years ago
unknown|6 years ago
[deleted]
agumonkey|6 years ago
ScottBurson|6 years ago
For the operation in question here, I suggest 'with'. This is what I have used in my own functional collections libraries; I think it originated in SETL.
masklinn|6 years ago
physicsyogi|6 years ago
https://clojuredocs.org/clojure.core/update