Why should file names intended for executables be valid identifiers?
Alex Parrill via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 17 11:38:10 PST 2015
On Tuesday, 15 December 2015 at 03:31:18 UTC, Shriramana Sharma
wrote:
> 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?
All files in D are modules. The only thing special about the
"main" module is that it exports a function called `main`, which
druntime calls at startup.
It's like asking why you need to have a class in Java that only
contains `public static void main(...)`, instead of just having
the main function itself; it's simply how D is designed, and it
reduces the number of special cases.
Though after compiling, module names are irrelevant; you can name
the binary whatever you want: `dmd -o whatever-filename.exe
my_module.d`
Name mangling is irrelevant; you can't have a dash in the module
name because it would make certain code ambiguous (ex.
`foo.my-module.bar`: is one module field reference or a
subtraction between two field references?)
More information about the Digitalmars-d-learn
mailing list