State Machines

  • Authors:
  • Dave Thomas;Andy Hun

  • Affiliations:
  • -;-

  • Venue:
  • IEEE Software
  • Year:
  • 2002

Quantified Score

Hi-index 0.00

Visualization

Abstract

We are surrounded by real-world state machines: ballpoint pen retractor mechanisms, vending machines, washing-machine controllers, digital watches. They are a trivial but underused technology that can simplify how we implement programs that must track how they got to their current state before handling a new event. However, many programmers feel that state machines are only useful when they're developing communication protocol stacks, which is not an everyday activity. This is unfortunate. State machines can be appropriate in surprising circumstances. Correctly applied, they will result in faster, more modular, less coupled, and easier to maintain code. State machines make it easy to eliminate duplication, honoring the DRY principle. They also let you write more expressive code, because you can specify intent and implementation independently. These are all good, pragmatic, reasons to investigate them further, so let's look at some simple state machine implementations and problems they can solve.