3 ms·
This was a very interesting presentation, but I think the author is too wedded to immutability to just come out and state the obvious: it’s a solution in search
by earthboundkid 5y ago
This was a very interesting presentation, but I think the author is too wedded to immutability to just come out and state the obvious: it’s a solution in search of a problem, and there’s not much good in using it as is. Yes, IF your problem can be decomposed into pure functional bits, that often makes a program easier to read. But if not, it’s wishful thinking to try bolting immutability onto the problem and hope that it helps. Returning state new objects is a sign that this problem doesn’t decompose the proper way to benefit from this approach!
In game dev, there’s a popular pattern called “Entity Component System” which deals with these problems quite well. The components are just blobs of pure data, like the state in the article, but instead of freezing them for no real reason, you compose systems to make them interact in predictable ways. It’s much easier to reason about, which makes it the right tool for this particular job.
- earthboundkid 5y agoThe premise of immutability is that this causes bugs: doA() doB() doC() and so the solution is instead of doing: State state doA(&state) doB(&state) doC(&state) you do State state state2 = doA(state) state3 = doB(state2) state4 = doC(state3) But obviously, the only difference between 2 and 3 is that 3 is a pain in the ass to type out. All of the benefit is there in 2 because you're explicitly declaring what it is that the functions are modifying, instead of having them modify unseen globals. There's no advantage to adding a ugly calling convention on top of that.