Hacker News new | ask | show | jobs
by aarpmcgee 1132 days ago
All I know is, the parts of my app that I implemented with state machines are by far the most stable, least buggy.

fwiw, if xstate feels like too much for whatever reason, https://thisrobot.life has seemed like a decent alternative to me.

4 comments

Same here, state machines are fantastic to extend state driven UIs without worrying about breaking existing behavior. If you find XState too verbose consider using a DSL that compiles down to JS like Lucy: https://lucylang.org
http://www.colm.net/open-source/ragel/ is good if you're more on the C side.

hmm… seaside… C side… has this been used for anything yet?

It seems like both of your links are projects from the same person, he must be passionated about state machines.
I am, thank you. : - )
Thanks for all your valuable contributions to this space! I have been curious if development on Lucy is continuing? I might like to port some of my existing machines over if the project is still active.
Can confirm.
Looks like Lucy compiles down to XState.
There's also a pared down, minimal version of xstate: https://github.com/statelyai/xstate/tree/main/packages/xstat...
I didn't know about this. Thanks a bunch.
You could also just make a very simple State machine. They don’t take a huge amount of code. you have a variable with the current state, you have a function that takes the previous state and the new State as arguments, now implement whatever logic you need. Not everything needs a library.

Pardon the unnecessary caps, I am using voice dictation.

When I need something lightweight I usually implement state machines using generators/coroutines when the language provides them, as they compose well and I find it easier to follow to control flow anyways.
I’m curious how you use and compose generator functions?

I created a JavaScript state machine library using them to define each state. https://github.com/JavaScriptRegenerated/yieldmachine

I imagine your approach must be different?

To compose generators I use `yield*` (or `yield from` in python) https://developer.mozilla.org/fr/docs/Web/JavaScript/Referen...* (note that last star is actually part of the link)

The main drawback with this approach is that it is easy to blow the stack, but it is not too hard to implement trampolining on top of it (by yielding the continuation to a wrapper generator)

To use the generator I send its inputs using `.next()` and obtain current state information, as shown on your library webpage.