separate and/or independent compilation

Myron Alexander someone at somewhere.com
Thu Jun 7 12:39:57 PDT 2007


Tibi wrote:
> Can someone please tell me a few words about separate compilation in D. A small example would be nice, if I`m not asking too much.
> 
> And one more thing, I haven`t understood very well what import does, is it similar to the #include statement from C++ or is it somewhat different?

Tibi,

The import statement is more similar to Python (or Java) than to C/C++. 
The #include statement instructs the c/c++ pre-processor to include 
source into the current source file which is why you have to be careful 
about what you put in the included file and also why you should have guards.

In D, the import statement imports a compiled module, not source.

Modules are actually similar to classes in that they have constructors, 
destructors, public and private elements, and they provide a namespace.

Their purpose is to provide functionality that the application can use, 
whether this is module globals, functions, classes, structs, type 
definitions, template definitions etc. In a module, you do not separate 
the declaration from the implementation, your implementation is the 
declaration.

Modules are a phenomenal tool for library writers, and they also provide 
a great way to break up an application into functional units.

In one sentence, modules provide the functionality of #include (and so 
much more) but with "special" binaries rather than source.

Regards,

Myron.


More information about the Digitalmars-d-learn mailing list