On Tuesday, 7 October 2014 at 07:33:24 UTC, Gary Willoughby wrote:
On Monday, 6 October 2014 at 21:24:56 UTC, AsmMan wrote:
Which practice do you use: if you need only one or two functions from a module:

import myModule : func, func2;

or (import whole module, assuming no function name conflits of course)

import myModule;

any words why one over the other are welcome.

I like the first one why it explicitly show why I'm importing such a module and I think (personally) it make code more easy to read/understand/maitain. Also it's very useful inside functions (local imports) where we can "overload" the function like in:

int f(int arg)
{
  import foo : f;

  return f(somethingElse, arg);
}

I used it recently.

Be mindful of this classic bug: https://issues.dlang.org/show_bug.cgi?id=314

Yeah. In the current state of affairs, please NEVER do selective imports in global scope. As a general rule, avoid imports in global scope anyways.

Reply via email to