Multiple modules per file
Paul Backus
snarwin at gmail.com
Mon Jun 20 16:34:04 UTC 2022
On Monday, 20 June 2022 at 15:48:08 UTC, Dennis wrote:
> What if you could just concatenate .d files?
>
[...]
> Other files can only `import pkg`, since the compiler can't
> find e.g. `pkg/sub.d`.
Well, presumably you could do it if you passed `pkg.d` explicitly
on the command line. But it wouldn't work with `dmd -i` (and
probably not with dub either).
This seems to me like a feature where the number of ways to use
it right (e.g., for package-internal modules that aren't intended
for outside use) is much smaller than the number of ways you
could potentially shoot yourself in the foot with it. If we adopt
this feature, I expect we'll end up getting a regular stream of
questions in the Learn forum where someone asks "why doesn't my
project build?", and the answer is "you need to put your modules
in separate files."
You could mitigate the issue by requiring that all modules in a
file belong to the same package, but then you lose out on some of
the desirable godbolt/run.dlang.io use cases, so it's not a clear
win.
More information about the Digitalmars-d
mailing list