On 08-Sep-2015 19:09, Brian Rogoff wrote:
On Tuesday, 8 September 2015 at 03:09:20 UTC, Rikki Cattermole wrote:
On 08/09/15 5:27 AM, Shammah Chancellor wrote:
void main() {
    import std.stdio : writeln;
    writeln("Hello world!");
}

-Shammah

It's not just an idiomatic way to code with local imports, it's a
compilation performance technique too.

I didn't read the DIP collection thoroughly (yup, D has a some
grotesqueries that would be nice to fix but I doubt will happen) but
local imports are one of the nice features of D (and Ada, and OCaml)
that I wish would be adopted in some other languages, like Nim and Julia.

I never thought of them as a performance optimization though. What's the
reasoning? Are the observed differences significant? From my POV
restricting the scope of an import makes local reasoning easier. I'd do
it even if it were slightly less performant!



Optimization comes when combined with templates - if template is not instantiated then the locals imports are not even read from disk.

--
Dmitry Olshansky

Reply via email to