really why module declarations?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Mar 26 13:58:24 PDT 2017
On Sunday, 26 March 2017 at 20:51:01 UTC, XavierAP wrote:
> I've perused both the spec[1] and Andrei's book, and I the idea
> I get is that module declarations are optional, recommended
> only in case of file names not being valid D names.
Module declarations are only optional in the most trivial case
that is rarely useful in real world code. I recommend you ALWAYS
use them (and always put a ddoc comment on them!), and moreover
that you avoid top name modules (use `myproject.modname` instead
of `modname`) to avoid conflicts.
If you don't, you are depending on implicit magic and just hoping
that there's no conflict from third party libraries, and those
lead to problems, almost guaranteed before long.
> if we have to be disciplined to keep it consistent with paths
> anyway?
That's false, the path is irrelevant to the D language, ONLY the
module declaration gives the canonical name. The path is just a
helper for automatic tools to find the module given an import,
but my preference is to ditch those things and actually just list
your modules by name anyway. Then everything works reliably and
consistently.
More information about the Digitalmars-d-learn
mailing list