News for hackers. Stuff that matters.
Re:Ask HN: Can a state machine be stateless? by acemarke on Sunday June 12, 2022 @05:04PM (#31718245)
Yes - you've just described a reducer function (ala Redux and React's `useReducer`).

Note that to be a _true_ Finite State Machine, the reducer function would need to be written to first check what state value it's currently in, _then_ decide if the input is relevant. Most Redux reducers are not actually written that way - they just update the state value based on the action, regardless of what the existing state was.

References:

- https://redux.js.org/style-guide/#treat-reducers-as-state-ma...

- https://dev.to/davidkpiano/redux-is-half-of-a-pattern-1-2-1h...

(source: I maintain Redux, and that Redux style guide entry and the additional blog post were written by David Khourshid, who is an expert on state machines.)

Re:Ask HN: Can a state machine be stateless? by proc0 on Sunday June 12, 2022 @06:13PM (#31718769)
I think the idea there is to think of all the actions as transitions in a state machine, however the state machine itself is the high level concept and not the implementation. A reducer function does not keep state, therefore not a state machine.
Re:Ask HN: Can a state machine be stateless? by davidkpiano on Sunday June 12, 2022 @05:24PM (#31718428)
Yep, the "stateless" part of the state machine is its transition function.