[erlang-questions] Any Erlang Devs Contemplating Elixir?

Loïc Hoguin <>
Sat Feb 27 11:54:57 CET 2016


On 02/26/2016 10:27 PM, Onorio Catenacci wrote:
> While there may be other considerations you want to keep in mind,
> there's one, to my mind, major point that's been neglected in the
> discussion of using Elixir: macros.
>
> I have been led to understand by people far more familiar with Erlang
> than I am that in order to use certain behaviours from OTP one has to
> write boilerplate code for several callbacks whether one wants to modify
> the behavior from defaults or not.
>
> Elixir's macros allow the library to provide default implementations for
> these callback functions.  Of course a developer can override the
> defaults if needed but not having to code what I don't need strikes me
> as a big advantage--especially if we're discussing a new developer who
> doesn't already know either Erlang or Elixir.

I'm not even sure what makes you think you need macros to provide 
default implementations? You don't. The gen_server for example has an 
optional callback with a default implementation: format_error. That it 
doesn't provide defaults for other callbacks is purely a design choice, 
and not a limitation of the language. You could trivially extend 
gen_server to make all callbacks optional, no need to have macros for 
that...

-- 
Loïc Hoguin
http://ninenines.eu
Author of The Erlanger Playbook,
A book about software development using Erlang


More information about the erlang-questions mailing list