3 ms·
> But why would you want to model the eventual update step itself as a pure function? So you can more easily debug the application across incorrect state chang
by masklinn 8y ago
> But why would you want to model the eventual update step itself as a pure function?
So you can more easily debug the application across incorrect state changes: if your update function is pure, you can very easily compare the state-before and the state-after.
This maintenance of observability is a superset of the unit-testing bit legulere talks about, and also opens up new features e.g. undo/redo becomes trivial, just re-set the state to whatever you need. If you modify the application state in-place, things become much more complex.
In a way git can be treated as that, the HEAD commit is the application state, when you "modify the state" you don't modify that commit in-place instead you create a new commit, then move HEAD to that new commit. Only the second step is impure. Even amending a commit is the latter, you're not actually modifying the old HEAD, you're creating a new one from it then moving HEAD from one to the other.
- lllr_finger 8y agoIn theory, this sounds great, and I am a huge proponent of functional programming. In practice, I've never seen it intuitive or useful. I've been at 3 companies now where "time travel" has never been used and web app development has been more painful than it needed to be. It feels very much like the proper (from a CS perspective) approach, but the language and libraries just aren't there to make it feel productive or fun. Is there any meaningful work being done to address this, or is it perhaps a boiling frog scenario?
- zsck 8y agoYou might be able to foster a deeper appreciation for some of these ideas by playing with Elm a little bit. Some time ago, they implemented time-travel in the standard debugger, and its a really wonderful feature. The site also has some demo apps that make it easy to play around with that time travel support. I agree that, currently, languages and frameworks don’t make things like time travel easy, insofar as such a feature is not often built in. However, technologies like Flux and Vuex are paving the way for such things to become mainstream. It’s worth pointing out, too, that both were inspired by Elm’s runtime architecture. Functional programming is, only in the last half-decade or so started to see a relatively dramatic rise in popularity. I think this trend will continue for a long time to come. For that reason, it’s worth learning more about these concepts.
- deleted 8y ago[deleted]
- masklinn 8y ago> In theory, this sounds great, and I am a huge proponent of functional programming. In practice, I've never seen it intuitive or useful. […] Is there any meaningful work being done to address this, or is it perhaps a boiling frog scenario? That's how Elm works and it's glorious. IIRC there are also clojurescript systems working that way (application state is an atom and updating it is a transactional CAS). But of course it also helps that the language itself lends itself to this, so you want a language which is expressions oriented and there persistent data structures are the default (or even the only) option. You can do the same thing in e.g. Javascript, but the language doesn't really help and it's easy to slip.
- KingMob 8y agoYup, the most popular Clojurescript React framework, Re-frame, works this way, and even with other frameworks, it's encouraged.
- kylestlb 8y agoLike another commenter said, using frameworks like flux and vuex allow you to utilize browser extensions that make the 'time traveling' debugging process easy.
- xg15 8y agoThat makes a lot of sense and actually sounds like a really interesting idea. Thanks for the explanation.