LINKDING

Login

Shared bookmarks

  • I've found myself coming back to this article several times when working on some hardware controller logic. Turns out Rust has some incredibly natural constructs for encoding state machines.

    TL:DR Have a generically typed state machine struct. Encode the states in structs. Encode the allowed transitions between states using the From trait. For example,

    // machine
    struct Machine<S> {
      state: S
    }
    
    // states
    struct State1
    struct State2
    struct State3
    
    // transitions
    //
    // state 1 -> state 2 -> state 3
    //    ^                     |
    //    |_____________________|
    
    // transition from state 1 to state 2.
    impl From<Machine<State1>> for Machine<State2> {}
    
    // transition from state 2 to state 3.
    impl From<Machine<State2>> for Machine<State3> {}
    
    // transition from state 3 to state 1.
    impl From<Machine<State3>> for Machine<State1> {}
    
    3 weeks ago | View Shared by greg
    |
  • TL;DR Start by using the technologies you know how to operate. If you're lucky enough to make something useful, the ease of operating the thing should outweigh the ease of building the thing.

    • Boring doesn't mean bad. Certainly don't choose boring and bad technology.
      Choose boring and good technology.
    • The ratio of known unknowns/unknown unknowns is high in boring technology.
    • The are many technical solutions to problems. But technology choices have
      long-term operational costs. If you're lucky enough to have something that's
      going to operate for a long time, the ease of operating the thing should
      vastly outweigh how easy it is to build the thing.
    • Choose new technology if building something is prohibitively difficult with
      the current technology you're operating. But make sure to really think through
      why it's difficult to build with your current technology.
    1 month ago | View Shared by greg
    |

User


Tags