[erlang-questions] avoid -import. Why?

Kostis Sagonas <>
Mon Jul 9 00:21:19 CEST 2007


Anthony Kong wrote:
> Hi, all,
> 
> In reading this resource (
> http://www.erlang.se/doc/programming_rules.shtml,
> ), I found this statement,
> 
> Don't use -import, using it makes the code harder to read since you
> cannot directly see in what module a function is defined. Use exref
> (Cross Reference Tool) to find module dependencies.
> 
> I do not think I understand why it is the case, and could not find the
> tool exref from the erlang distribution.
> 
> If anyone can shed some light, most appreciate.

Different people might give you different answers to this question.
Below are mine:

  1. In general, I do not like imports because they obscure they
     syntactic distinction of local vs. remote function calls.
     In Erlang, local function calls are of the form f(...) while
     remote ones of the form m:f(...).  With imports even remote
     function calls look of the form f(...)
     (I believe this is what the above statement is in the manual is
      referring to.)

  2. Occasionally, I want to find all calls to a function m:f/a and for
     that I use 'grep'.  Because of #1, there is no convenient one liner
     that can give me the places of all these calls.

Btw, the reference to the "exref" tool is most probably a reference ro 
"xref".

Kostis



More information about the erlang-questions mailing list