Multiple modules per file

Steven Schveighoffer schveiguy at gmail.com
Mon Jun 20 17:15:07 UTC 2022


On 6/20/22 12:34 PM, Paul Backus wrote:
> 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).

Another option is to use a different filename for such "package 
modules", like `.dp` for "d package"?

> 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."

Well, we already get messages because of the terrible error message you 
get when it can't find your module file (`module object is in object.d 
which cannot be read`). In this case, it might be even worse, suggesting 
that it can't read your module, when it's obviously in the right place.

In any case, I think the idea is worth exploring, but I don't know that 
it's a necessary addition.

-Steve


More information about the Digitalmars-d mailing list