coding practices: include whole module or only the needed function
Gary Willoughby via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Oct 7 00:33:23 PDT 2014
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
More information about the Digitalmars-d-learn
mailing list