On Wednesday, 30 September 2015 at 19:24:05 UTC, Jeremy DeHaan wrote:
On Wednesday, 30 September 2015 at 17:51:50 UTC, Jan Johansson wrote:
[...]

Like Adam said, the real difference between a .d and a .di file is that the .di file has all the guts removed and is just the declarations.

If using a .di file is really what you want, you could try something like this?

test.d:
module test;

interface IMyTest {
   void Write(string message);
 }


 IMyTest createInstance() {
    class MyTest : IMyTest {
     void Write(string message) {
         import std.stdio;
         writeln(message);
     }
 }

     return new MyTest;
 }

---------------

test.di:

module test;

interface IMyTest {
   void Write(string message);
 }


 IMyTest createInstance();

---------------

main.d:

import test;

void main() {
    auto p = createInstance();
    p.Write("Hello, World!");
}
--------------

and then

dmd test.d -lib -oftest

and

dmd main.d test.di test.a


Also like Adam said, dmd can create these .di files for you so you don't have to!

(This is untested, but should work/be close to working)

Thanks Jeremy,

Do you spot a weakness in your proposed code snip? The declaration for interface is done in two separate files, both test.d and test.di. Scattered declarations has never been a good idea. I know that I can ask the DMD to do declaration files for me, but the use case for that is to speed up building of executable.

But is it that the separation of declaration and implementation was never the intention in the design of D?

//Jan

Reply via email to