Re:Why Functional Programming Should Be the Future of Software
by AnimalMuppet on Friday November 04, 2022 @07:49PM
(#33475790)
"Simpler". If you're only single-threaded, the mutable structures are simpler.
If you're multi-threaded, you have to choose: Do I go with immutable, which means that the other thread gets something safe? It also means that the other thread gets something stale (out of date), which can have its own consequences.
Or do I use a lock or mutex, which means that I have to place guards in all the right places, which is error-prone and can break in weird ways if I miss one?
Or do I use mutable data without guards, and just let it crash? (Because it's probably going to crash if I do that...)
If it's ok to support only a single concurrent user of the value, then a mutable structure is more efficient. Even in Haskell we have mutable structures that can be used for such purposes.
The interesting question to me is, what should be the default? I think there is a good argument that it should be the safer, simpler immutable structures.