Thread overview
Keeping imports clean
Apr 01, 2012
Guillaume Chatelet
Apr 01, 2012
q66
Apr 01, 2012
James Miller
Apr 02, 2012
Guillaume Chatelet
Apr 02, 2012
Andrej Mitrovic
April 01, 2012
In C++ it clearly matters to have very clean dependencies to keep compilation time as low as possible ( Google even built a tool to check unused #include - http://code.google.com/p/include-what-you-use ).

So I was telling to myself it would be great to have the D compiler report about unused import because it might already have all the necessary information. But maybe such a tool already exists ? Or maybe this is simply irrelevant ?
April 01, 2012
On Sunday, 1 April 2012 at 22:13:00 UTC, Guillaume Chatelet wrote:
> In C++ it clearly matters to have very clean dependencies to keep compilation time as low as possible ( Google even built a tool to check unused #include - http://code.google.com/p/include-what-you-use ).
>
> So I was telling to myself it would be great to have the D compiler report about unused import because it might already have all the necessary information. But maybe such a tool already exists ? Or maybe this is simply irrelevant ?

in c++ it's text expansion, D imports are symbolic; it's not by far as relevant
April 01, 2012
On 2 April 2012 10:12, Guillaume Chatelet <chatelet.guillaume@gmail.com> wrote:
> In C++ it clearly matters to have very clean dependencies to keep compilation time as low as possible ( Google even built a tool to check unused #include - http://code.google.com/p/include-what-you-use ).
>
> So I was telling to myself it would be great to have the D compiler report about unused import because it might already have all the necessary information. But maybe such a tool already exists ? Or maybe this is simply irrelevant ?

D doesn't have includes, importing a module that you don't use doesn't matter because D only needs the imports to find function declarations. This is clear in the import syntax:

    import std.random : uniform //import only uniform from the std.random module

so it is a symbolic import, not a textual import. Also note that while D has .di ("D Interface") files, they are not required, and often people don't even bother with them, merely distributing the source.

So in short, it isn't relevant at all, since there is no preprocessor to f**k things up.

--
James Miller
April 02, 2012
Thanks for the quick answer. Indeed it's by far less relevant than for C++ but a build tool still needs to figure out the dependencies. I know D is very fast to compile but you still want to keep compilation at a minimum. Wouldn't it matter for a very big project ?
April 02, 2012
On 4/2/12, James Miller <james@aatch.net> wrote:
> So in short, it isn't relevant at all.

It is relevant to build times. Compare the build times of this:

import std.algorithm;
import std.array;
import std.conv;
import std.file;
import std.string;
import std.stdio;
import std.typetuple;
import std.typecons;
import std.traits;
import std.range;

void main() { }

With this:
void main() { }

First:
$ timeit dmd test.d
Elapsed Time:     0:00:00.296

Second:
$ timeit dmd test.d
Elapsed Time:     0:00:00.031

That's not a lot of time wasted but it does affect compile times a little bit. I wonder if DMD could be improved a bit in this regard.