Upgrade to Pro — share decks privately, control downloads, hide ads and more …

State machines in practice

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

State machines in practice

In this talk and live coding session we will see how state machines can help us with problems that often crop up in day-to-day development.

Code: https://github.com/pwm/fsm-talk

Avatar for Zsolt Szende

Zsolt Szende

August 22, 2017

More Decks by Zsolt Szende

Other Decks in Programming

Transcript

  1. Has any of you ever seen a variable, object property

    or database field named status, state or similar? Let's introduce the problem first:
  2. "The particular condition that someone or something is in at

    a specific time." (Oxford Dictionaries)
  3. "The particular condition that someone or something is in at

    a specific time." (Oxford Dictionaries)
  4. Claim: Much grief in software development arises from the inability

    to control state, i.e. from uncontrolled mutation of state.
  5. Claim: Much grief in software development arises from the inability

    to control state, i.e. from uncontrolled mutation of state. Proof: What do we do when we step through a program to debug a problem? We pause time to observe state.
  6. FSMs define how we can move between states ie. what

    is a valid move and what is an invalid move.
  7. So how do we move between states? The next state

    is a function of the current state and the event.
  8. So how do we move between states? The next state

    is a function of the current state and the event. (State, Event) ! State
  9. The next state is a function of the current state

    and the event. (State, Event) ! State This is called the transition function. So how do we move between states?