FSM advantages ?
Mon Jan 20 21:05:09 CET 2003
On Tue, Jan 21, 2003 Eduardo Figoli wrote:
} Could someone tell me the advantages of using
} FSM to Erlang receive & send messaging using functions (states), please ?
Until you have decided that you are an Erlang Guru you should use the
standard behaviours whenever applicable (knowing when they are applicable
being the only challenge). There are several really good reasons for this.
>From the "Programming Rules and Conventions" doc we are told:
"Whenever you have the same pattern of code in two or more
places in the code try to isolate this in a common function
and call this function instead of having the code in two
different places. Copied code requires much effort to maintain."
By utilizing the gen_fsm behaviour you have done this for much of the
common overhead of handling processes which implement finite state machines.
>From the "Design Principles" doc we are told:
"Applications must obey certain laws and must follow certain
protocols so that they present a uniform interface to the
Erlang runtime system. For example, they must be written so
that the code can be changed without stopping the system.
"The easiest way to program a new application is to make use
of the behaviours which are included in the system. A behaviour
is a "pattern of design" which can be used to build an
application. Applications which are programmed with the
standard behaviours automatically follow the required protocols."
By doing things "Erlang Way" you will get a lot of things for free. Just
look at the source file gen_fsm.erl and see if you want to understand all
that it is doing for you.
More information about the erlang-questions