Hipreme's #2 Tip of the day - Reducing .di files dependency

Hipreme msnmancini at hotmail.com
Sun Oct 23 20:12:46 UTC 2022


For reducing a D Interface file dependency when generating it 
with the `-H` flag for DMD, you can't import a module on the top 
level.
Take a look at that example:
```d
module a;
import std.stdio;
void printSomething(string a)
{
    writeln(a);
}
```

If you generate the .di interface file while using dmd, it will 
pretty much generate:

```d
module a;
import std.stdio;
void printSomething(string a);
```
Using the import inside the function scope, it will make the work 
easier for dmd:
```d
module a;
void printSomething(string a)
{
     import std.stdio;
     writeln(a);
}
```

Will actually generate only:
```d
module a;
void printSomething(string a);
```

This will greatly reduce the number of import and dependencies 
you need if you ever need to distribute a library.


More information about the Digitalmars-d-learn mailing list