D Language Imports and modules

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Syntax

  • module my.package;
  • import my.package;
  • import my.package : function;
  • import fancyName = mypackage;
  • import my.package : fancyFunctionName = function;

Remarks

Modules automatically provide a namespace scope for their contents. Modules superficially resemble classes, but differ in that:

  • There's only one instance of each module, and it is statically allocated.
  • There is no virtual table.
  • Modules do not inherit, they have no super modules, etc.
  • Only one module per file.
  • Module symbols can be imported.
  • Modules are always compiled at global scope, and are unaffected by surrounding attributes or other modifiers.
  • Modules can be grouped together in hierarchies called packages.

Modules offer several guarantees:

  • The order in which modules are imported does not affect the semantics.
  • The semantics of a module are not affected by what imports it.
  • If a module C imports modules A and B, any modifications to B will not silently change code in C that is dependent on A.


Got any D Language Question?