coding practices: include whole module or only the needed function

AsmMan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Oct 6 14:24:54 PDT 2014


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.


More information about the Digitalmars-d-learn mailing list