Hipreme's #4 Tip of the day - Don't use package.d

ryuukk_ ryuukk.dev at gmail.com
Sat Nov 5 01:34:04 UTC 2022


On Friday, 4 November 2022 at 10:57:12 UTC, Hipreme wrote:
> Package.d is a real problem existing on our currently modules 
> design. First is that it means to take the directory name to 
> use as a module.
>
> This is a problem for 3 reasons:
>
> 1. You won't be able to find your module by the file name. This 
> is incredibly common, for instance, in Visual Studio Code, when 
> you hit CTRL+P and type the file name, nope, you will need to 
> write path/to/folder/package.d, beyond that, when you search 
> package.d there will be so many files with the same name.
>
> 2. As being an exception to how the module system works, this 
> has already caused me a few headaches (inexplicable bugs), that 
> happens with symbols aliasing, when the time it happened, I had 
> no idea on what it could be and I don't even remember how I 
> solved, instead, I only knew it was related to package.d.
>
> 3. I'm currently having a bug on my API module that every 
> duplicated file name, even when located at different 
> directories(modules), are generating duplicate symbol. The 
> major problem is that this is currently undebuggable, as the 
> MSVC Linker does not show the full directory of the 
> libraries/object files that caused this clash, not even the 
> symbol!
>
> The duplicate symbol currently only happens in MSVC Linker, 
> which makes me think if the bug is in the D language or the 
> linker itself, as on LLD this does not happen.
> So, my current advice is always try making your file names 
> unique, this will bring a much better debuggability in your 
> project.

i use that feature a lot, just search with the folder name, then 
"package"

https://i.imgur.com/cHb7isl.png

it's also very useful to avoid having all of your code in a giant 
unreadable single file

it's also very useful to avoid using dub.. just an import path to 
the folder and that's it

https://i.imgur.com/Wy6WOXK.png

also very useful when you want to simplify using importc, put 
your c files under the c folder, and the package.d, public import 
the c files, and you can put some helper code in D there, very 
nice to have


More information about the Digitalmars-d-learn mailing list