4 ms·
> if you choose immutable structs, your interface for users is EXTREMELY annoying. For example, if they want to update `x` from `1` to be `2` That's the whole
by 331c8c71 4y ago
> if you choose immutable structs, your interface for users is EXTREMELY annoying. For example, if they want to update `x` from `1` to be `2`
That's the whole point of immutability that you can't "just update". I fail to see how obscure magical updates on immutable (?) structs like advertised in [1] or [2] e.g.
using Accessors
@set obj.a.b.c = d
are beneficial. Note that there is _zero_ explanation on the front page of what the above snippet does, how to use it and what actually happens under the hood. One example of why I personally don't have much trust in JuliaLand.
Scala has `x.copy(field=newval)` for its (immutable) case classes. Note how clear it is that one is making a copy. Lenses are also outside of the stdlib (e.g. [3]).
[1] https://github.com/JuliaObjects/Accessors.jl https://github.com/JuliaObjects/Accessors.jl
[2] https://github.com/jw3126/Setfield.jl https://github.com/jw3126/Setfield.jl
[3] https://www.optics.dev/Monocle/ https://www.optics.dev/Monocle/
- JanisErdmanis 4y agoAs I understand, the idea of immutability and usage of packages like Setfield.jl to change struct fields is a safety feature for concurrency. When putting it in as an argument to a function, you can be sure that it would not be changed during execution introducing races without needing to acquire a lock. Also, state machines become easier to reason about when immutables are used.