4 ms·
This enum is a list of states. Immediately should one think about a proper tool to handle it, which usually is a finite state machine. FSMs are somehow underap
by nine_k 4y ago
This enum is a list of states.
Immediately should one think about a proper tool to handle it, which usually is a finite state machine. FSMs are somehow underappreciated outside of comm protocols and GUIs. They are an adequate tool for quite a few "backend" or "data representation" tasks though.
What the original post suggests is to timestamp the latest state transition. The approach is trivially obvious if you explicitly track state transitions as a part of the logic of your FSM.
- jpollock 4y agoThat's a great way of phrasing it. A boolean can be a FSM in hiding. Tracking FSM transitions is the change history/transaction log, isn't it? It would be: {timestamp, old_state, event, new_state} If we convert booleans to timestamps for the FSM, I end up with: timestamp not_configured; timestamp being_provisioned; timestamp active; timestamp disabled; timestamp deleted; Which would cause confusion when there are multiple FSMs in the same database record. We could isolate each FSM into its own column. It still makes it kind-of hard to decide what's the current state. The set of timestamps needs to be considered and sorted, going from field to {field_name, timestamp} and then sorting by timestamp and extracting the max. It would make "select count(*) from customers where current_state = 'active'" brittle - the addition of a new state would require all existing queries to change.