11 ms·
I haven't used D, but in Haskell we have the same module name == file name thing. The only time I don't like it is when we have nested modules, the parent and c
by kccqzy 8y ago
I haven't used D, but in Haskell we have the same module name == file name thing. The only time I don't like it is when we have nested modules, the parent and children modules are not in the same directory:
import A -- compiler reads A.hs
import A.B -- compiler reads A/B.hs
Thus, two semantically related modules are now in different directories.
Python, IMO, handles this correctly by having __init__.py support inside directories. It's theoretically less elegant because of the special name, but in practice leads to better file organization.
Same for Rust, but even better, because one can define nested modules in the same file. So you can either define a new module in the same file, put it in a different file named by the module, or put it in the file `mod.rs` inside the directory named by the module.
- JoshTriplett 8y ago> The only time I don't like it is when we have nested modules, the parent and children modules are not in the same directory: > import A -- compiler reads A.hs > import A.B -- compiler reads A/B.hs That has to happen at some level, assuming subdirectories; otherwise, what would "import A.B.C" refer to?
- ben-schaaf 8y agoD also has package.d for the same effect as python. It works quite well as package is a keyword and thus can't be used as a regular module anyway.
- p0nce 8y agoBut package.d could lead you to overdepend on too many modules too :) it's mostly great for end applications rather than internal to libraries.
- ben-schaaf 8y agoSure, but that's not specific to package.d. See the earlier convention of all.d or d.d. That's the trade-off with having public imports. I don't see how this is related to my comment though?