Community
D has three widespread alternatives.
Write a module named all.d that includes all the modules from your package. (Literally "*" โ "all"). After that, you simply do import com.paroboy.io.all;
I see more and more that D developers are using _ for this. Therefore, for this purpose they write a module called _.d . Similar to # 1, you do import com.paroboy.io._;
A relatively new addition to the D programming language is the package.d module, which can be used to import a package. More on this in the next DIP: http://wiki.dlang.org/DIP37 . If I remember well, DMD has supported it since version 2.04. (Documentation: http://dlang.org/module#PackageModule )
I myself use approach number 1, because it is obvious what is happening. Although # 2 and # 3 can confuse people reading the original D file, especially the third. A valid question that someone might ask is: "Why the hell am I importing a package? But import is only for modules! ??"
All that nothing prevents you from having a separate module for each class, I would not recommend it. D is truly a modular language, so take advantage of this. Group all your types in one module D. This is my advice, and this is "path D".
Note: There is a (big) semantic difference between the Java module and the D module, as you probably already noticed. I am primarily a Java programmer, so I know how confusing Java programmers can be when playing with D. Java classes in the same package, which often take advantage of package-level access. However, classes inside the same module behave like โfriendsโ in C ++.
Speaking of Java modules , they should have shipped with Java 8 (real modules!), But have been delayed and hopefully will be included in Java 9.
UPDATE: We conclude, after chatting on FreeNode (IRC) with some members of the D-Programming-Language , that it is now really safe to use the package attribute. It behaves as specified in the specification.
source share