[<<][softarch][>>][..]
Sat Aug 17 11:01:42 EDT 2019

Back to boring? How to write state machines.


- decouple via circular buffers.  buffers are great in that they have
  only one parameter: their size.  often a buffer creates "protocol
  wiggle room", e.g. protocol oriented programming: the tokens that go
  into the buffer can be chosen to make the reading end simpler.

- write it in polling style.  this still makes it possible to use
  event or interrupt driven approach by only polling when an event
  comes in.

- buffer + poll allows the use of smart peek.  i.e. the buffer does
  not need to contain parsed tokens.  the peek function can do the
  tokenizing, which is often simpler to do than to perform tokenizing
  at the sending end.

- represent state explicitly, i.e. don't use sm.h tricks when not
  necessary, i.e. prefer factoring into simpler machines.

  with explicit state, a poll method looks like:
  - try to read a token
  - dispatch on (token, state)





[Reply][About]
[<<][softarch][>>][..]