|
|
|
|
|
by sillysaurusx
1957 days ago
|
|
I came back to edit my comment and remove the harsh words, but you left a very kind response. Sorry. This is actually a fascinating example: https://lucywang000.github.io/clj-statecharts/docs/get-start... ... because it highlights precisely my criticism. ;; define the machine
(def machine
(fsm/machine
{:id :lights
:initial :red
:context nil
:states
{:green {:on
{:timer {:target :yellow
:actions (fn [& _]
(println "transitioned to :yellow!"))
}}}
:yellow {:on
{:timer :red}}
:red {:on
{:timer :green}}}
:on {:power-outage :red}
}))
I just ... don't understand why anyone would do it this way. The code itself already says what to do. Adding this sort of data only subtracts from clarity with no additional flexibility.You might argue that the data model makes it flexible. But I look at that and go, that's what a function is for. The only thing you need is `(println "transitioned to :yellow!")` inside of a function called transition-to-yellow, or if you're feeling adventurous, a function called transition-to which takes yellow as an argument. |
|
It's much easier for me to introspect, and I can easily build dynamic state-machines by changing a data structure, take a look at interceptors[0] as an example. There the stack is dynamically alterable based on what is within the request and each piece of middleware can look at the current context, analyse it and behave accordingly.
I write a lot of workflow based systems with dynamically changing functionality based on user input. This sort of thing is invaluable in that context.
- [0]: http://pedestal.io/guides/what-is-an-interceptor