[erlang-questions] Erlang code reuse

Federico Carrone <>
Fri Aug 22 22:11:01 CEST 2014


Huxi, you should check https://github.com/opscode/mixer from the Chef guys.
I use it a lot and it works perfectly fine.

In Elixir you got protocols:
https://pminten.github.io/blog/2013/09/11/elixir-patterns-mixins/

They are awesome! I recommend that you try elixir.

Protocols <http://clojure.org/protocols>, if I am not wrong, come from
Clojure land. In a way they are remotely similar to duck typing in
Ruby/Python but better (subjective opinion).

However even with mixer/mixins, protocols or duck typing I am pretty sure
that they would not be useful for the supervisor2 scenario. In that case,
as Anthony Ramine pointed out, the supervisor should give you some option
to insert the new functionality.

Regards,
Federico.





On Fri, Aug 22, 2014 at 3:35 PM, Tyler Margison <> wrote:

> I'm not an Erlang expert, so others are more than welcome to correct me on
> this, but I do not believe Erlang allows "code reuse" in the manner you are
> suggesting. Erlang has behaviors, which are modules that define an
> interface and may have additional functionality of their own (see
> gen_server), but there is no way to inherit from a module and override
> select functions. I feel like this isn't a common scenario, though. In all
> of my own projects I very rarely, if ever, find myself re-writing entire
> modules to suit my own needs.
>
> PS: I thnk Elixir <http://elixir-lang.org/> might be able to do this, but
> I haven't looked at the documentation in-depth for a while and I may be
> wrong.
>
>
> On Thu, Aug 21, 2014 at 10:56 AM, Huxi Li <> wrote:
>
>>  Hello all,
>>
>> I am surprised to see the way the following module is coded when studying
>> rabbit MQ server:
>>
>>
>> https://github.com/rabbitmq/rabbitmq-server/blob/master/src/supervisor2.erl
>>
>> It is a duplication of erlang's supervisor.erl with minor changes.
>>
>> So my question is :  Are there better ways of code reuse in erlang
>> without duplication of code as found in the above example ?  Some sort of
>> polymorphism ?
>>
>> Thanks in advance.
>>
>> Huxi LI
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>


-- 
http://federicocarrone.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140822/44449062/attachment.html>


More information about the erlang-questions mailing list