On Thursday, 9 November 2017 at 04:58:19 UTC, Chuck Allison wrote:
As others have said, rename the .d file, since files are considered modules. I have since changed my notes to reflect this change. Sorry for the confusion.

Chuck Allison


When coming to a new language I tend to write lots of little snippets (or copy/save examples), and then I name those snippet files according to the thing being 'snipped'. But, if you do that in D (and many will do that), and you don't have some module namespace in your snippets, you'll run it the same trouble I did.
I spent a day debugging because of this ;-)

So, can I suggest that all code samples, by default, have: module test; (or something at the top).

I'd also recommend making this issue of module namespace, one of the *first* things people learn, when coming to D, especially that fact, that the compiler will create a namespace for you (if you don't) based on the file name.

So if you're writing a book, perhaps that should be in your mind too ;-)

btw. As I've mentioned on other posts, the current version of GDC (as opposed to DMD and LDC) will compile such code without issue (i.e when you don't give a module name), and it will correctly work out the correct namespace to use(apparently a bug - but a nice bug ;-)


Reply via email to