[erlang-questions] Is -extends() used in any projects?

José Valim <>
Tue Jan 22 15:49:46 CET 2013

Is anyone actually relying on the runtime aspect of -extends?

The examples above use -extends to extend another module and it happens at
It means that, if you call extending:call() it will delegate propagate at
runtime to extended:call(). In erlang/otp master, this propagation happens
via '$handle_undefined_function'.

However, this could also happen at compilation time. We can imagine a parse
transform that handle -extends() in the following way: when you declare
-extends(foo) inside a module, the parse transform will get all the
functions in the module foo that are not yet defined in the module bar and
generate stubs like:

    call(Arg1, Arg2) ->
      foo:call(Arg1, Arg2).

This has the following advantages:

1. It is faster at runtime;
2. Doesn't require '$handle_undefined_function';
3. Calling bar:module_info(exports) will also reveal the functions
"inherited" from foo, so it is clearer in behaviour too

However, it has the following disadvantages:

1. It requires module foo to be compiled before bar. I don't believe this
is an issue as it is easy to tweak your Makefile or your rebar.config;
2. If the module foo is hot loaded in production, the new functions added
in foo are not going to appear in bar if it is not recompiled as well

Even if someone is relying on this particular aspect (2) of extends, all
they have to do is to accordingly include their updated version of bar in
the upgrade recipes as well. It seems to be a fair trade-off for faster and
simpler runtime semantics, unless, of course, I am missing something.

*José Valim*
Skype: jv.ptec
Founder and Lead Developer

On Tue, Jan 22, 2013 at 6:39 AM, Brujo Benavides <>wrote:

> I can think of this module<https://github.com/inaka/edis/blob/master/src/edis_gb_trees.erl#l9> where
> I used it to extend some basic Erlang functionality in a similar way than
> what Kresten at basho-labs <https://github.com/basho-labs> did in hanoidb<https://github.com/basho-labs/hanoidb/blob/master/src/gb_trees_ext.erl#L3>
> I also did a quick search on github to see who else was using it for open
> source projects. This is what I've found:
> - People at Beam.js <https://github.com/BeamJs/> use it in erlv8<https://github.com/beamjs/erlv8>
>  for their objects<https://github.com/beamjs/erlv8/blob/master/src/erlv8_fun.erl#L5>
>  - Ivan Dubrov <https://github.com/idubrov/> uses it in siperl<https://github.com/idubrov/siperl>
>  for transactions<https://github.com/idubrov/siperl/blob/master/apps/sip/src/transaction/sip_transaction_client_invite.erl#L9>
>  - claimstrade <https://github.com/claimstrade> uses it in maru<https://github.com/claimstrade/maru>
>  for its models<https://github.com/claimstrade/maru/blob/master/lib/maru_models/src/maru_model_users.erl#L10>
> On Jan 22, 2013, at 3:44 AM, Björn Gustavsson wrote:
> -extends() was mentioned when we first talked
> about removing parameterized modules, so we
> assumed that we needed to emulate -extends()
> as well as parameterized modules.
> It seems to be a good time to ask the question:
> Is -extends() used by real projects? Do we really
> need to emulate it?
> BTW, -extends() is described here:
>   http://www.erlang.se/euc/07/papers/1700Carlsson.pdf
> --
> Björn Gustavsson, Erlang/OTP, Ericsson AB
> _______________________________________________
> erlang-questions mailing list
> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130122/4a40b6cd/attachment.html>

More information about the erlang-questions mailing list