D言語リファレンスから:
モジュールは、ソースファイルと1対1で対応しています。モジュール名は、パスと拡張子が削除されたファイル名です。
ただし、モジュール名は引き続きファイルで明示的に指定されます。
module foo;
これのポイントは何ですか?モジュールがファイルに対応している場合、コンパイラがファイル名からそれらが何と呼ばれているのかを推測できないのはなぜですか?
D言語リファレンスから:
モジュールは、ソースファイルと1対1で対応しています。モジュール名は、パスと拡張子が削除されたファイル名です。
ただし、モジュール名は引き続きファイルで明示的に指定されます。
module foo;
これのポイントは何ですか?モジュールがファイルに対応している場合、コンパイラがファイル名からそれらが何と呼ばれているのかを推測できないのはなぜですか?
same page a bit down (emph mine)
The ModuleDeclaration sets the name of the module and what package it belongs to. If absent, the module name is taken to be the same name (stripped of path and extension) of the source file name.
this means that if you want to put a module in a package you have to explicitly specify it is (like Java's package
declaration) and given the strange propensity of people to use odd/foreign directory names you can't rely on checking for source/src/import in the path
the reason that filename and module name don't have to be the same can be so you can use a .di for import and use several versions of the actual code using -c switch to create the .obj file for linking of the different versions (though fiddling with the import path is handier for that)
それは推測できます。モジュール名を指定する必要はありません。ただし、モジュール名を指定することはできます。これにより、必要に応じてまったく別の名前を付けることができます。この典型的な例は、ファイル名が有効なモジュール名でない場合です (例: my-module.d)。このような場合、module
宣言を使用して有効なモジュール名 (my_module など) を指定できます。
モジュール名をファイルの先頭に置くのが一般的で、通常、モジュール名はファイル名と同じですが、モジュール名がファイル名と完全に一致しないようにすることで、柔軟性が向上します。
個人的には、モジュールにファイル名以外の名前を付けることは一般的に悪い考えだと思います。また、ファイルが有効なモジュール名でない場合は、ファイル名を変更して有効なモジュール名にする必要があると主張します。 、しかし、それらが一致しないことを可能にする余分な柔軟性が価値があると判断されたようです. だから、それは言語にあります。