Given that...

1. importing a module makes it compile the entirety of it, as well as whatever it may be importing in turn
2. templates are only compiled if instantiated
3. the new package.d functionality

...is there a reason *not* to make every single function/struct/class separate submodules in a package, and make *all* of those templates? Unnused functionality would never be imported nor instantiated, and as such never be compiled, so my binary would only include what it actually uses.


std/stdio/package.d:
    module std.stdio;
    // still allows for importing the entirety of std.stdio

    public import std.stdio.foo;
    public import std.stdio.writefln;
    __EOF__


std/stdio/foo.d:
    module std.stdio.foo;

    void fooify(Args...)(Args args)
    if (Args.length > 0)
    {
        // ...
    }

    void fooify()()
    {
        // don't need this, won't compile this
    }
    __EOF__


std/stdio/writefln.d;
    module std.stdio.writefln;

    // nevermind the incompatible signature
    auto writefln(string pattern, Args...)(Args args)
    if (!pattern.canFind(PatternIdentifier.json))
    {
// code that doesn't need std.json --> it is never imported
    }
    __EOF__


What am I missing?

Reply via email to