What if you could just concatenate .d files?
You could write a file pkg.d
that looks like this:
/// Helper module
module pkg.sub;
string name;
/// Main application module
module pkg.app;
import pkg.sub;
void main()
{
writeln("hello ", name);
}
/// My package
module pkg;
public import pkg.app;
public import pkg.sub;
And then this works:
dmd pkg.g
No new syntax like module {}
or fancy tricks like mixin("module x;")
, it would be as if the compiler splits up the file into multiple files as a preprocessing step.
Other files can only import pkg
, since the compiler can't find e.g. pkg/sub.d
.
Why?
It's best practice to keep modules small, but it's not always fun to deal with many small files.
In many text editors/IDEs it's easier to scan through a file than a file tree.
It's also easier to distribute. Notice how some libraries use stand alone files for convenience: arsd, stb, the SQLite Amalgamation. Sometimes, your code has to be condensed to one string of text for a web IDE, like codingame, godbolt, run.dlang.io, or when just posting in the forums / bugzilla.
And, of course, the recent discussion about private
to the class
, where putting a class
in its own file is rejected as a solution.
Thoughts?