3 ms·
tl;dr Software programmers continue to fail to grasp that "protocol" means "state machine". News at 11. Even beyond just "use an actual state machine", progr
by bsder 6y ago
tl;dr Software programmers continue to fail to grasp that "protocol" means "state machine". News at 11.
Even beyond just "use an actual state machine", programmers don't grasp that you need to think about:
1) What is my state now?
2) What are my inputs now?
3) What are my outputs now?
4) What is my state next?
5) Where/when do I transition from state now to state next and does it need to be atomic?
Conflating any of these results in bugs. And not using state machines explicitly always results in conflating these.
One of the most important overlooked concepts in protocols is that "time" is an input (interestingly, Carmack talks about this in game development, too). Timeouts and errors are a state like anything else.
- valenterry 6y ago> And not using state machines explicitly always results in conflating these. Not true - (pure) functional programming also enforces that you do exactly that. Even more, its rule-set also enforces that time must be an input.
- marcosdumay 6y agoMost pure functional idioms for handling a protocol are state machines, some of them in disguises, others plain ones. The ones that aren't state machines are very limited and often enough way too verbose. In particular, FRP is worth noticing as being exactly a set of states that change by means of events. It's a nice idiom for composing very complex state machines, but isn't even disguised.
- valenterry 6y agoI think it is the other way around. FRP goes further than state machines, in that it forbids any side effects. E.g. you could build a state machine that, when in a certain state and getting a certain event, responds or acts by printing the current time. A classical state machine will thus behave different, depending when it receives the event. However, in FRP you _must_ either parametrize the event with the current time, or you need to have something _outside_ of the statemachine (such as an effect interpreter) which handles effects such as printing the current time. A classic state machine does not have these restrictions.
- lmm 6y agoGeneral state machines are useless as an abstraction: they're fundamentally noncompositional, which makes them impossible to reason about as soon as they get big enough. Many things can be represented as state machines, just as any program can be represented as a sequence of machine instructions; that doesn't mean that's a useful representation for working with.