News for hackers. Stuff that matters.
Re:State Machines II by baby on Sunday August 28, 2022 @07:59PM (#32633401)
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 {
      /* ... \*/
    }
  }
Re:State Machines II by jcelerier on Monday August 29, 2022 @03:49AM (#32635678)
> 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

Re:State Machines II by baby on Monday August 29, 2022 @04:56PM (#32643445)
If your list of allowed transition is in a single place how is it making your logic harder to understand vs easier?