Writing closed source programs in D?

Jonathan M Davis jmdavisProg at gmx.com
Fri May 31 08:35:39 PDT 2013


On Friday, May 31, 2013 13:06:13 Regan Heath wrote:
> .di files are .d files without the function bodies etc. There are issues
> with templates and auto, but we will eventually have nice solutions for
> those.

The only problem with auto is that the type can't be inferred without the 
function body. But all of the information is there. So, all you have to do is 
make it so that the function doesn't return auto (or so that the variable 
declaration uses the actual type instead of auto). For non-templated 
functions, that's trivial. .di generation could automate that better, but it's 
not a big deal.

The situation with templates is basically the same as it is with C++. They 
have to go in the interface/header file and always will. There's no way around 
that, because the code importing the header/interface file actually needs the 
full definition. If the compiler supported some sort of intermediate format, 
then you could provide partially compiled templates, but pretty much all of 
the information would still have to be there (just in a less human readable 
format), and you can't even partially compile much of a template without the 
arguments to instantiate it with anyway. So, you'd pretty much just be putting 
the same template definition in a binary format instead of text, which wouldn't 
stop much of anyone from figuring out what they looked like.

The reality of the matter is that if you want to hide your implementation, you 
don't use templates. It's impossible to actually hide them due to the fact 
that they're merely templates for generating code rather than actual code.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list