Templating everything? One module per function/struct/class/etc, grouped by package?
JR via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon May 12 01:37:42 PDT 2014
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?
More information about the Digitalmars-d-learn
mailing list