I have no idea - you haven't told me what problem you want to solve -
you've told me the
technique you wish to use to solve the problem.
This is a bit "back to front" - I'd like to *start* with the the
problem then figure out how to solve
it - not *start* with the idea that you want FSMs and events and so on
and not tell me what the
problem is.
I can't possibly recommend any technology without knowing what the problem is.
Regarding FSM in erlang - these are easy:
state1() ->
receive
event1 -> state2();
event2 -> state3()
end.
state2() ->
receive
event3 -> state4()
..
end.
whatever - not really worth getting grey hair over
Event driven programming is with Erlang spectacles on - not a wonderful idea.
Events are a poor substitue for the lack of concurrency and non-blocking reads.
If I had a language with a) only one thread of execution and b)
blocking I/O then you
know what I'd do - I'd invent event based programming.
Let me explain what I think happened ...
Once upon a time there was a sequential processor, that could run only
one sequential program.
The program did the following
a: start -> read -> compute -> write -> compute -> read ->
compute ... -> stop
ie it interleaved computation with reads and writes.
If the reads blocked - who cared - it's only doing one thing - a
consequence of this
architecture was "the program should not crash" - since there is only
one thread if it crashes
you have a BIG problem - so we invent "defensive programming"
Now we want to do TWO or more things at the same time:
a: start -> read -> compute -> read -> compute -> read ->
compute ... -> stop
b: start -> read -> read -> write -> compute -> read ...
Now - horrors - read stops the system - it blocks, and writes are
problematic we two things
might write the same object at the same time.
Enter - the big global write lock and event based programming
We transform a: into
a: start -> read and on_read_complete(a1)
a1: compute -> read and on_read_complete(a2)
a2: compute -> read and on_read_complete(a3)
etc. and the same for b - the result is the software is a big mess
look at Javascript
$('#result').load('ajax/test.html', function() {
alert('Load was performed.');
});
This is typical jquery javascript code
load("blaa", fun)
means read fun and when the read completes call fun.
Now look what happened:
Simple code like
a: start -> read -> computer -> write -> read ->
got broken into a mess of callbacks and you need a TOOL to help you - enter
FSM modeling the callback style a -> ... read on-read_complete(a1) becomes
a total mess and needs a graphic tool to solve the problem that should never
occurred in the first place.
If read is NON blocking (ie does not block other processes) then you
don't need callbacks.
What about crashing?
When you have ONE thread crashing is a BIG DEAL
But now we have millions of thread - who cares if one crashes - nobody
- "let it crash"
But wait a moment - fault tolerance then? - "let some other guy fix the error"
Who? some other process. Which process? - enter the link - "the linked
processess"
So now we can chuck the idea of defensive programming - don't do it.
Bye bye to 80% of your code that did error checking :-)
Erlang encourages a different mind-set - you can have hundeds and of
thousands of processes
each running sequential easy to write code
a: start -> read -> compute -> read -> read -> write
and not a FSM or event framework on the horizon
Try it - since (again) I don't know what your problem is I can't
really make more than generic observation - but from the Erlang point
of view events and so on are a very "70's" way of programming.
Cheers
/Joe