3 ms·
I think this is not going far enough. This is way too much code to show allowed transitions. IMO a state machine should be define first in a list of valid state
by baby 4y ago
I think this is not going far enough. This is way too much code to show allowed transitions. IMO a state machine should be define first in a list of valid state transitions.
Perhaps something like this:
/// the states
states States {
Green,
Orange,
Red,
}
/// the valid transitions
transitions SomeTransitions for States {
fn green_to_orange: Green => Orange,
orange_to_red: Orange => Red,
red_to_green: Red => Green,
}
// now create a context
struct Context { /\* ... */ }
// implement the transitions
impl SomeTransitions for Context {
pub fn green_to_orange(self) -> self {
/* ... \*/
}
}
- jcelerier 4y ago> IMO a state machine should be define first in a list of valid state transitions. I once did this for a project and I really regretted it, when the state machine grew to ~15 states with maybe 80% of the complete graph in terms of transitions, it became extremely hard to read and follow as one would need to jump back and forth all over the place in the code
- baby 4y agoIf your list of allowed transition is in a single place how is it making your logic harder to understand vs easier?