Templating everything? One module per function/struct/class/etc, grouped by package?

Ary Borenszweig via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 12 08:58:20 PDT 2014


On 5/12/14, 5:37 AM, JR wrote:
> 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.

Welcome to Crystal :-)

In Crystal, every function and method is templated. When you compile 
your program, only what you use gets compiled. A simple hello world 
program is just 16KB.

And contrary to what Jonathan M. Davis says, compiling programs is very 
fast. In fact, compilation times might indeed be faster, because you 
don't need to compile unused code. And the resulting binary is as small 
as possible. And the error messages are pretty good, also.

But D has an entirely different philosophy, so I don't think they will 
like it. I also once suggested "auto" for parameters, but they didn't 
like it.

I'm just saying this to say that yes, it's possible, and no, it doesn't 
hurt compilation times or error messages.


More information about the Digitalmars-d-learn mailing list