On Monday, 6 January 2014 at 07:02:03 UTC, Andrei Alexandrescu wrote:
Yah, but modules transitively imported in foo and bar need not be loaded eagerly. That's where the win comes from. Took me a while to figure.

Andrei

Yes, it would help in certain cases (writeln doesn't have template constraints), but we should still use more static and scoped selective imports to reduce coupling.
Otherwise we can't improve on a quite common case.

import foo_dep, bar_dep;

void foo(T)(T) if(isSomeFoo!T) {}
void bar(T)(T) if(isSomeBar!T) {}

When using foo the compiler will have to import bar's dependencies and vice versa. Refactoring the imports gets rid of this problem.

import foo_dep : isSomeFoo;
static import bar_dep;

void foo(T)(T) if(isSomeFoo!T) { import foo_dep; /*..*/ }
void bar(T)(T) if(bar_dep.isSomeBar!T) { import bar_dep : someBar; /*..*/ }

Reply via email to