Why should file names intended for executables be valid identifiers?

Shriramana Sharma via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 14 19:31:18 PST 2015

I understand that module names need to be valid identifiers in that other 
modules would need to import them. But when a file is intended to be just an 
executable, why is it mandatory to give it a module declaration with a valid 

For instance, hyphens are often used as part of executable names on Linux, 
but if I do this:

$ dmd usage-printer.d

I get the following error:

usage-printer.d: Error: module usage-printer has non-identifier characters 
in filename, use module declaration instead

I expect it should not be difficult for the compiler to see that this D file 
is not a module being imported by anything else or even being compiled to a 
library which would need to be later imported. In which case, why does it 
insist that the file should be given a valid module name?

Shriramana Sharma, Penguin #395953

More information about the Digitalmars-d-learn mailing list