5 ms·
Programmers are bad at managing state when they forget to use the tools made for managing state. I've had to work on code bases where the state was "implicit" a
by captainbland 3y ago
Programmers are bad at managing state when they forget to use the tools made for managing state. I've had to work on code bases where the state was "implicit" and encoded in a bunch of different fields which "grew" over time and it's a full on nightmare. Even a rudimentary state machine which makes both application state and transitions between states explicit feels like a super power by comparison.
- analognoise 3y agoWhat tool do you recommend to do so?
- alwaysbeconsing 3y agoSum type is key, called "discriminated union" sometimes generally. In Rust this is an `enum`. Simulated in some languages as tuples with tag first element. Discrete number of states, attaching information only relevant to each single state. Thus, never have invalid combination of other fields.
- mrkeen 3y agoI think in this context 'state' means 'state which changes over time', not necessarily the shape of the state at rest. Turning it off and on again will fix mutable state, not poorly-typed state.
- kjqgqkejbfefn 3y agoJust look for state-machine (finite state automata) on github https://github.com/search?q=state-machine&type=repositories https://github.com/search?q=state-machine&type=repositories This is a very common pattern in Ruby to manage state. It's especially useful to guard entering impossible states with respect to business logic and figuring out what went wrong. Something along the lines of: Can't transition Command from 'ordered' to 'to-deliver': paid() == false look at this gem https://github.com/pluginaweek/state_machine https://github.com/pluginaweek/state_machine to get an idea of what features are possible
- j45 3y agoClassic state management must be taught and learned to understand the why of current state management solutions and why so many come and go.