[erlang-questions] Avoiding boilerplate code when using gen_server

Torben Hoffmann torben.lehoff@REDACTED
Wed Mar 21 12:48:38 CET 2012


I was sitting with a co-worker - who is proficient in OCaml and lots of 
other stuff and he is now learning Erlang - and then he comes up with a 
good question on the amount of boilerplate code when implementing a 

 From the API functions you call out to gen_server:call/2 and on top of 
that you need to implement a handle_call/3 function clause that matches 
whatever format you used for wrapping the incoming message.

The question was: why don't you use an IDL (Interface Definition 
Language) approach instead of writing all that code that has to match up 
in order to work?

So the idea would be to write a my_server.idl file and from that 
generate two files:

  * my_server_stub.erl
      o This holds all the public APIs that clients may call.
      o It calls my_server_skeleton as dictated by the IDL file.
  * my_server_skeleton.erl
      o gets all all the calls from the my_server_stub and calls

The job then is to implement my_server.erl according to the type specs 
derived from the IDL file.

Has anyone looked into this before?
I have tried searching for it, but since IDL is so tightly coupled with 
CORBA I didn't really find anything but the ic application from the 
Erlang/OTP distribution.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120321/ea95bcc2/attachment.htm>

More information about the erlang-questions mailing list