Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 07, 2013 having a folder containing dots in the import path | ||||
---|---|---|---|---|
| ||||
Hi guys! I just made the discovery that putting a D source file named "d" in a directory named "a.b.c" with a module declaration like: module a.b.c.d; works as expected (can be imported via import a.b.c.d;). This is actually pretty cool and useful (and I hope nobody removes this feature now, that I mentioned it!). I was just wondering if it is ok to rely on this or if it is unintended/unspecified behaviour that might change? Thanks! Best regards, Robert |
March 07, 2013 Re: having a folder containing dots in the import path | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert | On Thursday, 7 March 2013 at 16:31:10 UTC, Robert wrote:
> Hi guys!
>
> I just made the discovery that putting a D source file named "d" in a
> directory named "a.b.c" with a module declaration like:
> module a.b.c.d;
>
> works as expected (can be imported via import a.b.c.d;). This is
> actually pretty cool and useful (and I hope nobody removes this feature
> now, that I mentioned it!). I was just wondering if it is ok to rely on
> this or if it is unintended/unspecified behaviour that might change?
>
> Thanks!
>
> Best regards,
>
> Robert
This is how the D module system works, so it's a feature and won't be removed.
|
March 07, 2013 Re: having a folder containing dots in the import path | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | On 03/07/2013 08:49 AM, simendsjo wrote: > On Thursday, 7 March 2013 at 16:31:10 UTC, Robert wrote: >> Hi guys! >> >> I just made the discovery that putting a D source file named "d" in a >> directory named "a.b.c" with a module declaration like: >> module a.b.c.d; >> >> works as expected (can be imported via import a.b.c.d;). This is >> actually pretty cool and useful (and I hope nobody removes this feature >> now, that I mentioned it!). I was just wondering if it is ok to rely on >> this or if it is unintended/unspecified behaviour that might change? >> >> Thanks! >> >> Best regards, >> >> Robert > > This is how the D module system works, so it's a feature and won't be > removed. Wouldn't it be confusing at least to programmers that 'import a.b.c.d;' might also match file d under the path a/b/c? I wouldn't use a dot in directory names. Ali |
March 08, 2013 Re: having a folder containing dots in the import path | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Thursday, March 07, 2013 15:06:42 Ali Çehreli wrote:
> Wouldn't it be confusing at least to programmers that 'import a.b.c.d;' might also match file d under the path a/b/c?
>
> I wouldn't use a dot in directory names.
Definitely not. It's a foolish thing to do. It only works here, because the module was told that it was a.b.c.d, in which case the directory structure wasn't what was used to find the module. Folders and files that are packages and modules really should match the names of the packages and modules that they are and use valid identifier names.
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation