Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
brucou
@brucou
May you be successful in achieving your vision within the constraints that you have set for yourself.
Marton Sari
@sarimarton
@brucou , is your state machine library scxml compliant?
And is it a state machine or statechart library?
brucou
@brucou
Statecharts = state diagrams + depth + orthogonality (i.e. concurrency) + broadcast-communication
Kingly = hierarchical extended state machine ~ state diagrams + depth. No orthogonality, no messaging. Just a function.
Marton Sari
@sarimarton
Hmm
I find scxml xmls really appealing and ergonomic in PUG format. JSON is horribly verbose, and partly Yaml too, for the same reason, that is, XML attributes can't be written on the same line. But XML itself is verbose too because of the closing tags. PUG is winning for me.
Marton Sari
@sarimarton
so how do you handle parallel states? How would you do the microwave example from the scxml spec site?
brucou
@brucou
I am not familiar with that example, but the basic idea is that every parallel region can be modelled as a separate machine, each machine is put in a process, the processes communicate through message passing or events.
the point being if you have concurrency, you need a concurrency model (here I just used the process model), and then you need process communication.
sounds complicated but you do that kind of thing quite often when you use Rxjs
brucou
@brucou
flatMapLatest, zip for example are operators which handle concurrency in a declarative way. So requests = flatMapLatest(keyPressed => makeAPIcall(keyPressed)) means that for each key pressed, you will have a async process (API call), and you may have several of them concurrently, and the operator will take care of handling hte communication so that you get only the results of the latest one who communicated back its results. It is declarative so you don't really have to care about how the concurrency and communication are implemented.
brucou
@brucou
three kinds of concurrency: shared-state, message passing, and declarative.
statecharts are shared-state (the state of the state chart). That is the more complex type :locks, semaphores generally. Statecharts escape locking, but instead have a complex mechanism of queuing steps, small steps and big steps, I actually dont remember exactly how the whole thing works but it is documented somewhere.
actors, CSP are message passing.
rxjs would be mostly declarative
brucou
@brucou
by the way, you can always imagine translating any behaviour of any state machine in SCXML, so in that sense any state machine library is SCXML compliant. The reverse would not be true though. That is a ton of SCXML markup would not be able to be converted into specific library format. So the only interest of bidirectional SCXML compliance would be if you have some very nice tools already existing that you can reuse to modelize your system, output the corresponding SCXML and then you convert that to your library format.
I seriously doubt there is any such tool that are beneficial to graphical user interface programming. But I might be wrong, and if the tools exist for sure I will evaluate them. Always better to reuse when you can.
siassaj
@siassaj
@brucou what’s a good resource for learning these more advanced state machine concepts
We’ve used them in simpler cases where they model life cycles of business rules and entities
brucou
@brucou

what’s a good resource for learning these more advanced state machine concepts

what are you referring to specifically? statecharts? State machines are pretty simple to use, you don't really need to read a book to understand the concept. Extended state machines are state machines with memory (i.e. state which you can update and read from). Hierarchical state machines are machines whose control states can themselves be machines (which can themselves be machines etc. so you get a hierarchy that way). State transducers are state machines which produce outputs. That is about it really. Looking up stuff on Wikipedia here should be enough.
Statecharts are for sure more complex because it complects several unrelated things together (concurrency and communication). There are the Harel book, and then Ian Horrocks book which makes for good references (lots of pages but nice read and thorough treatment of the subject). Otherwise there are several short lessons that you can find online that are being taught in schools. That one gave me the idea of writing the chess game with state machines.

and then there are the really advanced papers which discuss the edges cases and semantic issues around including concurrency in statecharts and alternative models. That is not really worth reading till you have a good idea of the subject.
brucou
@brucou
There is a statechart commnunity where you can ask those questions. I focused more on state machines, I described above how the two intersect, if you forget about concurrency it is almost the same thing.
siassaj
@siassaj
i think statechart is the more interesting concept but i want my statemachine foundations to be correct
i noticed that with many implementations it's hard to send an event + payload
seems to be frowned upon
(it seems to me)
i've never attempted to model business logic in purel state machine terms
and i'd like to attempt that also
Matthew Hayden
@mrehayden1
anyone else having typescript 3.6 woes?
I just accidentally bumped to typescript=3.6.3 and .event from @cycle/dom was causing errors everywhere I used it
John Pallister
@synchromesh
@siassaj @brucou I found Miro Samek's Practical Statecharts in C/C++: Quantum Programming for Embedded Systems to be very good, but that was, goodness, over fifteen years ago now and there might well be better books on the subject...
siassaj
@siassaj
@synchromesh its an interesting topic isnt it
siassaj
@siassaj
@brucou are we allowed to pass event arguments in a formal state machine implementation
i've seen people set data, then fire the event
brucou
@brucou
@siassaj you are allowed to do whatever the specific library you use allow you to do, right? Formally speaking the notion of parametric events (i.e. events with data) seems to come more often with extended state machines.
brucou
@brucou
@siassaj were you referring for example to https://github.com/jakesgordon/javascript-state-machine ? I saw that he has a 3.x newer version with funny stuff, like wildcards, dynamic transitions and other rarities.
siassaj
@siassaj
No I haven’t used any statemachines in JavaScript yet
I did build a bunch of state modelling modules where functions were built in the spirit of event machines, and it worked
But not exactly a state machine so no formalism
siassaj
@siassaj
@brucou yeah just didn't know if event payloads were allowed
if it broke deteriministic behaviour
brucou
@brucou
I don't think they are event payloads in basic state machines, but in extended state machines, there are.
why would it broke deterministic behaviour?
brucou
@brucou

To recenter the subject of state machines on cycle.js, I want to emphasize that a cycle component is f::Sources -> Sinks where Sources is either an event source, or an event source factory, and Sinks are the commands to run. That makes cycle.js quite a natural fit for using state machines, as long as the machine computes commands from events. The component becomes something like

function f(sources){
  const {eventSource$} = sources;
  const commands$ = eventSource.map(fsm);

  return {
    sink1: commands$.map(extractSink1Command).filter(Boolean)
    ...
  }
}

where extractSink1Command:: Command -> Maybe Sink1Command, and commands$:: Stream Command

brucou
@brucou

In practice, your machine will take several event sources, so const commands$ = eventSource.map(fsm); may become const commands$ = merge(eventSource1, eventSource2, ...).map(fsm)

When you do it like this, there is no need to handler reducers, use isolation etc. The machine already handles the necessary state in an isolated way. That may or may not have better ergonomics according to the taste du jour. But for complex logic, I really think that it is a pretty attractive option.

This message was deleted
Marton Sari
@sarimarton
One thing I find myself frequently using is .compose(dropRepeats()). With combine's and merge's and map's, stream event propagations can easily go out of hand, and then at some point you have to control and clean it up with this. Maybe this is another phenomenon which belongs to the UI characteristics. I think dropRepeats could be a default behavior with MemoryStreams
Marton Sari
@sarimarton
or some default somewhere :D