Skip to content

Commit a4bc75c

Browse files
committed
Rewrote "state machine" because it's a popular hit
It averages roughly 5th place on Google and DDG for the search term "state machine"
1 parent 25a8a57 commit a4bc75c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

what-is-a-state-machine.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
sitemap:
3-
lastmod: 2019-07-08
4-
priority: 0.4
5-
description: A state machine is a machine that can be in exactly one state at a time, reacting to events by transitioning between states.
3+
lastmod: 2020-04-10
4+
priority: 0.7
5+
description: A state machine is a way of modeling program state so that a program will always be in exactly one state at any one time.
66
keywords:
77
- state
88
- state machine
@@ -23,8 +23,6 @@ And further:
2323
2424
A state machine is _also_ a visual depiction of such an abstract machine.
2525

26-
Understanding state machines is almost the same as understanding **statecharts**. In many ways, statecharts are the "bigger brother" of state machines, designed to overcome some of the limitations of state machines.
27-
2826
## Example
2927

3028
Here is a visual depiction of a simple state machine. It is a model of a simple on/off switch.
@@ -39,8 +37,18 @@ Some observations over this machine.
3937
* When the machine _enters_ the "on" state, a side effect occurs. A light is turned on.
4038
* When the machine _exits_ the "on" state, another side effect occurs. A light is turned off.
4139

40+
This simple state machine is comparable to a boolean variable—which can either be true or false—that controls the _on_-ness of something.
41+
42+
## What is state anyway?
43+
44+
Program state is the _set of all variables in a program and their values at any point in time_ (see [Wikipedia](https://en.wikipedia.org/wiki/State_(computer_science)#Program_state)). A program or software component that has five independent variables, that each could be true or false, then it could in theory _be_ in any of 32 states (2 to the power of 5 = 32). However, a program will often have _invalid_ states, and in traditional software, the variables are carefully checked and manipulated in such a way that these invalid states don't happen.
45+
46+
A state machine is an alternative way of modeling program state: Instead of defining independent variables, a machine is crafted specifically to handle what states are possible, and when a machine is a given state, what _next_ state is allowed. Those five independent boolean variables are replaced with a single _state machine_ which intrinsically can only be in valid states.
47+
4248
## Relationship with statecharts
4349

50+
Understanding state machines is almost the same as understanding **statecharts**. In many ways, statecharts are the "bigger brother" of state machines, designed to overcome some of the limitations of state machines.
51+
4452
State machines are closely related to their bigger brother, _statecharts_. A statechart is essentially a state machine that allows any state to include _more_ machines, in a hierarchical fashion. This is to overcome some of the limitations that are inherent to state machines.
4553

4654
The primary goal of statecharts.github.io is to help you to understand statecharts. An understanding of state machines is a nice side effect. [What is a statechart?](what-is-a-statechart.html)

0 commit comments

Comments
 (0)