2 ms·
From the first paragraph: > ... Architectures that work well in other languages generally don’t adapt well to Rust, mostly because they rely on shared mutable
by Barrera 4y ago
From the first paragraph:
> ... Architectures that work well in other languages generally don’t adapt well to Rust, mostly because they rely on shared mutable state and that is not idiomatic Rust, to put it mildly. ...
The author doesn't mention Redux (the architecture), which is surprising. There are three principles[1]:
1. The global state of your application is stored in an object tree within a single store.
2. The only way to change the state is to emit an action, an object describing what happened.
3. Changes are made with pure functions.
In other words, the components of an application never mutate the state tree directly. Rather, they emit actions which re-generates the state tree without mutation.
This style of state management is compatible with Rust's ownership model.[2] The emphasis on pure functions (that clone state rather than mutate) means that it's not necessary for your application to alias mutable references, which I'm guessing underlies the "generally don't adapt well to Rust" part of the claim.
[1] https://redux.js.org/understanding/thinking-in-redux/three-principles https://redux.js.org/understanding/thinking-in-redux/three-p...
[2] https://github.com/jaredonline/redux-rs https://github.com/jaredonline/redux-rs
- ______-_-______ 4y agoI think Redux is similar enough to Elm that it's not worth mentioning separately. Redux plays fast and loose with types whereas Elm uses types strictly; that's probably why Elm is mentioned more often in the context of Rust. He does mention Redux in passing if you expand "Advanced topic: comparison with Elm"
- cultofmetatron 4y agoredux architecture is just a global scan(). more or less what the elm architecture is as well.
- raphlinus 4y agoThe other responses have this right. I think the Redux pattern is similar enough to Elm that I didn't feel a need to make a finer distinction. I'll also say this: the tools that Rust provides for reasoning about mutation are powerful and principled. A central philosophy of Rust is that mutation isn't the problem, it's shared mutable state. If you believe that philosophy (and I do), then restricting yourself to pure functions over clonable state feels like tying one hand behind your back. I hope I've made the case that providing finer grained access to mutable app state is an approach at least worth exploring.
- mkishi 4y agoApart from the architectural similarity, Elm also predates both Redux and Flux, even being referenced in Redux's Prior Art page [1]. [1]: https://redux.js.org/understanding/history-and-design/prior-art https://redux.js.org/understanding/history-and-design/prior-...