Since memory serves I use to name files with - instead of the more common _
Thread overview |
---|
June 21, 2021 is there a way to: import something = app-xyz-classes-something; ? | ||||
---|---|---|---|---|
| ||||
June 21, 2021 Re: is there a way to: import something = app-xyz-classes-something; ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to someone | On Monday, 21 June 2021 at 03:32:58 UTC, someone wrote: >Since memory serves I use to name files with - instead of the more common _ The module name has to be strict and "-" is not allowed. From the manual: >If the file name of a module is an invalid module name (e.g. foo-bar.d), you may use a module declaration to set a valid module name:
Tested on Windows/dmd - does NOT work :( |
June 21, 2021 Re: is there a way to: import something = app-xyz-classes-something; ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to frame | On 6/21/21 4:55 AM, frame wrote: >On Monday, 21 June 2021 at 03:32:58 UTC, someone wrote: >Since memory serves I use to name files with - instead of the more common _ The module name has to be strict and "-" is not allowed. From the manual: >If the file name of a module is an invalid module name (e.g. foo-bar.d), you may use a module declaration to set a valid module name:
Tested on Windows/dmd - does NOT work :( It does work. However, you have to tell the compiler the file to compile. When an import is used, the compiler does 2 stages:
So if you provide the file name to the compiler as part of the set of files to compile, it should work. e.g: foo-bar.d:
app.d:
compiled like:
That being said, I strongly recommend just to name the file the same as the module name. -Steve |
June 21, 2021 Re: is there a way to: import something = app-xyz-classes-something; ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Monday, 21 June 2021 at 13:29:59 UTC, Steven Schveighoffer wrote: >It does work. However, you have to tell the compiler the file to compile. Which completely ignores filenames if the compiler is satisified. You may assume by reading the manual that the compiler would make an automatic translation for illegal characters to "_" as module name to find a file in a directory - and that is not case. Supplying the filename manually makes this naming convention somehow irrelevant, if you get my point. |
June 21, 2021 Re: is there a way to: import something = app-xyz-classes-something; ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Monday, 21 June 2021 at 13:29:59 UTC, Steven Schveighoffer wrote: >It does work. However, you have to tell the compiler the file to compile. When an import is used, the compiler does 2 stages:
So if you provide the file name to the compiler as part of the set of files to compile, it should work. e.g: foo-bar.d:
app.d:
compiled like:
That being said, I strongly recommend just to name the file the same as the module name. -Steve Ironically I was already doing this on a shell script carrying all my source file names and switches for DMD, but since I started to, I did not retest changing back the names on the file system to a-b-c. I changed them right now and it works flawlessly. Issue solved. Thanks for the tip Steve :) ! |
June 26, 2021 Re: is there a way to: import something = app-xyz-classes-something; ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Monday, 21 June 2021 at 13:29:59 UTC, Steven Schveighoffer wrote: >That being said, I strongly recommend just to name the file the same as the module name. Although you made it clear that you do not favor this use-case I am really satisfied with your solution because, at least to me, has some pros; consider the following type "namespace" where sm stands for stock manager ie: the app prefix (and fw for framework ie: the common library):
... linked as following with this build script:
... and on each module:
Naming directory/files/type-namespace and aliasing this way allows me to:
What I like most of it is that it scales well for big and complex apps while being really flexible ... and neat :) |
June 26, 2021 Re: is there a way to: import something = app-xyz-classes-something; ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to someone | On Saturday, 26 June 2021 at 02:19:18 UTC, someone wrote: >What I like most of it is that it scales well for big and complex apps while being really flexible ... and neat :) If you pass each file to the compiler like in your script then every naming convention becomes irrelevant because the compiler does not need to do a file system lookup anyway and a module "foo_bar" could be also in the file xyz.d. But however, to have files organized is always a good idea. |
June 26, 2021 Re: is there a way to: import something = app-xyz-classes-something; ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to frame | On Saturday, 26 June 2021 at 04:24:05 UTC, frame wrote: >If you pass each file to the compiler like in your script then every naming convention becomes irrelevant because the compiler does not need to do a file system lookup anyway and a module "foo_bar" could be also in the file xyz.d. You put it in far better words than mine -this paragraph should be in the docs :) |