[erlang-questions] The gen server simplified (how it works)

David Mercer dmercer@REDACTED
Mon Apr 25 22:52:44 CEST 2011

On Wednesday, April 20, 2011, Joe Armstrong wrote:

> Many users seem to use the gen_server for absolutely everything
> and often force their problems to fit the gen_sever even though the
> gen_server is not appropriate for their problems.
> . . .
> This is *why* we made the gen_server abstraction. You can write well-typed
> sequential code (the handle_call and init functions) to parametrize
> a concurrent behavior, ie you need to know nothing about concurrency to
> get the job done. We've "abstracted out" the concurrency.
> Things become problematic when you do not entirely understand the
> Maybe the abstraction is inappropriate for your needs. I have seen many
> of code where the gen_server *is* inappropriate. The acid test is "does
> gen_sever code look like spaghetti" if the answer is yes then all you have
> is shoe horn the applications into an inappropriate form. In this case
> you should ditch the gen_server and roll-your own.

I am not sure what you are advocating in gen_server's stead.  Some others on
this thread seem to be pushing gen_fsm as the alternative, but I don't think
that's what you are arguing, since you have generally preferred lightweight
non-OTP processes.  Are you arguing for more use of gen_fsm, more creation
of roll-your-own OTP-compliant processes using proc_lib and sys, or less
reliance on the OTP framework and more use of plain old Erlang?

More information about the erlang-questions mailing list