Author Topic: D-language Modules/Imports  (Read 12628 times)

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
D-language Modules/Imports
« on: March 05, 2014, 10:11:00 AM »
Hi,

I've studied the Module/Import system of the D language (dlang.org). D is a
language that tries to be a better C++. It's good to see that there are lots
of similarities between D and C2. This means that more people make the same
choices, which probably means that can't be that bad.

Similarities are:
  • Concept of Package(C2)/Module(D)
  • Package/Module have public/private symbols
  • D static import are equal to C2 use
  • D non-static import are equal to C2 use local (allows symbol use without prefix)
  • Use(C) / Import(D) statement
  • Import Aliases: use as (C2) / import io = c.stdio (D)

Differences are:
  • D modules are single file, whereas C2 Packages can consist of multiple files
  • D allowes Modules to be prefixed with a 'Pakage', c.stdio
  • C2 has a build-system, D uses external one (like Make)
  • D allows public import, C2 doesn't have this concept
  • D allows multiple import in 1 line: import a,b, C2 doesn't
  • D allows scoped import, C2 doesn't
  • C2 doesn't need the module scope operator like D (.x)
I'm very interested in the public import feature. Does anyone have experience with this
(drawbacks, large-scale problems, advantages?)

Another think I'm still thinking about is the concept of something bigger than
C2 Packages. In D these are called Modules, but D also has a concept of Package.
The only use I discovered was that the compiler automatically looks for pkg.module
in pkg/module.d. But maybe in C2 we can use this for something else..

Finally, I think 'Module' reflects the meaning a bit better than 'Package', so
maybe C2 will also follow this. Package was currently chosen to create distinction
from clang's 'Modules' concept.

Anymore?

Bas


DerSaidin

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: D-language Modules/Imports
« Reply #1 on: March 24, 2014, 12:06:44 PM »
The differences you list are mainly syntax. In the interest of exploring more significant differences:

What are C2's advantages compared to D?
What is a project that you think C2 would be a better choice than D?

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: D-language Modules/Imports
« Reply #2 on: March 27, 2014, 08:02:58 AM »
I did not have the intention to compare C2 to D here; just compare the import system, since that is very similar in
need/purpose. D can be seen as a 'replacement' for C++. C2 is covering the same domain is C. So whenever you
would use C for something, you could use C2. But for software that usually written in C++ now, maybe D can be
used. So the domains are different. C2 is a lower-level language than D, with all advantages/disadvantages.