Simpler UI Logic With Finite State Machines
I find &quot;state&quot; to be quite an overloaded term, especially in React land, so I use &quot;stage&quot; instead for the various state machines in our applications. It&#x27;s caught on in our org and I&#x27;ve heard no complaints.<p>State machines are great but they get quite complicated when you have two machines interacting at some point. I find this happens quite a bit for complicated UIs, like a data grid with filter and search controls, in-row controls, a preview pane on the side, etc. Things that can be reasonably simple become overly complicated as you try to cram everything into a state machines model.<p>It&#x27;s hard to give concrete examples... but it happens often. I even find myself doing it.<p>Rust enums (sum types) are really good for doing FSMs, as they:<p>- Allow you to add fields to each state, which makes it easier to understand what each state is for at a glance.<p>- Prevent you from accessing fields for a different state at the wrong time.<p>- Make it easy to do nested states, without that nestedness existing for states that don&#x27;t need it.<p>- Provide exhaustiveness warnings for if you&#x27;re not handling a case.<p>I do wish more languages had sum types.