State Machines in Programming

Comments discuss modeling software systems, processes, and even brains as state machines, along with various implementation techniques like recursive functions, tail calls, and transition functions in different programming languages.

📉 Falling 0.5x Programming Languages
1,110
Comments
19
Years Active
5
Top Authors
#9156
Topic ID

Activity Over Time

2008
1
2009
13
2010
19
2011
22
2012
17
2013
28
2014
37
2015
39
2016
61
2017
37
2018
72
2019
68
2020
96
2021
98
2022
111
2023
153
2024
120
2025
115
2026
3

Keywords

detail.cfm CPU CPS TCO game.c UPS FedEx DFA OP WLOG state state machine machine state machines transitions states turing machine machines turing function

Sample Comments

0110011 Jun 12, 2018 View on HN

Eh, just write a state machine.

gdprrrr Oct 11, 2023 View on HN

Not OP, but in functional languages, state machines are often simply a function (State, Input) -> State

rtontic Jun 20, 2023 View on HN

It's all just one big state machine.

mycall Oct 20, 2023 View on HN

It still is an amazing state machine.

murderfs Oct 1, 2022 View on HN

That just means that the actual state machine has intermediate states for each transition.

hitekker Dec 31, 2015 View on HN

direct link to image visualizing the complexity of the state machine required: https://i.stack.imgur.com/SrUwP.png

davidkpiano Jun 12, 2022 View on HN

Yep, the "stateless" part of the state machine is its transition function.

eru Aug 8, 2017 View on HN

You can implement state machines as a set of mutually-recursive functions with one state = one function. Works very well, is tail-recursive and not trivially replaced by loops.

masklinn Aug 4, 2017 View on HN

Sure but now you can't really drive the state machine can you? The state machine has to drive you and provide callbacks for state transitions, something like that.edit: ah I see you'd extract the entire manipulation in a function which would return a terminal type or union thereof, yeah that'd work I guess.

lilyball Jul 12, 2022 View on HN

State machines can often be implemented with a set of functions that each handle a single state and then tail-call into the function for the next state.