On Saturday, 5 July 2014 at 16:35:31 UTC, Andre Tampubolon wrote:
I've been reading the newsgroup for a while, and it seems that one of the reason folks like D is because it supports module.

My question is: what does module mean?
A quick google pointed my this page: http://dlang.org/module.html.
Still cannot understand it, though :)

How does it differ from the old C's #include?

For example, consider the hello world in C.

#include <stdio.h>

int main(void){
        printf("%s\n", "Hello world...");
        return 0;
}

The C preprocessor while replace the line "#include <stdio.h>" with the content of stdio.h itself.

While in D:

import std.stdio;

void main(){
        writeln("Hello world...");
}

Does that mean the compiler take the "definition" of writeln itself from stdio.d and paste it into my program? Pardon my ignorance, because I'm not versed in compiler theory.

You might find the clang docs on C++ modules worthwhile, though they do it somewhat differently from D:

http://clang.llvm.org/docs/Modules.html

An #include simply copies and pastes the entire contents of the C/C++ header into your source, which can happen over and over again in a large project with no include guards, while modules are a more sophisticated way of separating code.

Reply via email to