www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [Feature Request] Single name access when module name and content are

reply tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
I only want to discuss an idea here. I am hoping see some nice 
pros and cons from people.

---

We have this feature in D:

template something(T){
     void something(T value){ writeln( value ); }
}

something("Hello");

Because the name of template and function match each other, 
"something" is accepted as name of function.

---

Especially in Phobos, and also in my own libraries, there are 
name duplications. The cause of this is that we want to define 
things separately, hence defining a new module for them, but the 
name of module and class name becomes same. My thought/request is 
that, if the name of module and a 
variable/constant/struct/class/template/enum that is in that 
module matches each other exactly, as seen in the example above, 
without name duplication, access should be passed to that 
variable/con... etc.

Currently, by using package.d, this is supported in "made up" way 
by putting programmer into duplication again while using 
directories, but for module itself, I do not see any solution 
currently.

Currently, I couldn't have found any issue about adding this 
feature. So is the proposal.

module my.big.lib.createFile;

void createFile( string fname ){}

Somewhere else in the code universe:

my.big.lib.createLib("FSociety.dat");
Dec 25 2015
next sibling parent reply tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
On Friday, 25 December 2015 at 15:45:16 UTC, tcak wrote:
 I only want to discuss an idea here. I am hoping see some nice 
 pros and cons from people.

 [...]
My mistake at the end. It should be: my.big.lib.createFile("FSociety.dat");
Dec 25 2015
parent reply default0 <Kevin.Labschek gmx.de> writes:
On Friday, 25 December 2015 at 15:46:23 UTC, tcak wrote:
 On Friday, 25 December 2015 at 15:45:16 UTC, tcak wrote:
 I only want to discuss an idea here. I am hoping see some nice 
 pros and cons from people.

 [...]
My mistake at the end. It should be: my.big.lib.createFile("FSociety.dat");
https://dlang.org/spec/module.html check the section on "Static Imports" does this do what you want?
Dec 25 2015
next sibling parent Satoshi <satoshi gshost.eu> writes:
On Friday, 25 December 2015 at 17:08:04 UTC, default0 wrote:
 On Friday, 25 December 2015 at 15:46:23 UTC, tcak wrote:
 On Friday, 25 December 2015 at 15:45:16 UTC, tcak wrote:
 I only want to discuss an idea here. I am hoping see some 
 nice pros and cons from people.

 [...]
My mistake at the end. It should be: my.big.lib.createFile("FSociety.dat");
https://dlang.org/spec/module.html check the section on "Static Imports" does this do what you want?
I think he want something like: new System.Collections.List!int; against new System.Collections.List.List!int; If you have module System.Collections.List; class List(T) { ... } If the module and class names match, remove one.
Dec 25 2015
prev sibling parent tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
On Friday, 25 December 2015 at 17:08:04 UTC, default0 wrote:
 On Friday, 25 December 2015 at 15:46:23 UTC, tcak wrote:
 On Friday, 25 December 2015 at 15:45:16 UTC, tcak wrote:
 I only want to discuss an idea here. I am hoping see some 
 nice pros and cons from people.

 [...]
My mistake at the end. It should be: my.big.lib.createFile("FSociety.dat");
https://dlang.org/spec/module.html check the section on "Static Imports" does this do what you want?
You misunderstood what I propose, please reread it again. One example how the current problem is: https://dlang.org/phobos/std_digest_digest.html std.digest.digest.digest!MD5("The quick brown fox jumps over the lazy dog"); See those 3 digest one after another. Haven't seen anything like this in neither C# nor Java nor Delphi.
Dec 25 2015
prev sibling parent tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
On Friday, 25 December 2015 at 15:45:16 UTC, tcak wrote:
 I only want to discuss an idea here. I am hoping see some nice 
 pros and cons from people.

 ---

 We have this feature in D:

 template something(T){
     void something(T value){ writeln( value ); }
 }

 something("Hello");

 Because the name of template and function match each other, 
 "something" is accepted as name of function.

 ---

 Especially in Phobos, and also in my own libraries, there are 
 name duplications. The cause of this is that we want to define 
 things separately, hence defining a new module for them, but 
 the name of module and class name becomes same. My 
 thought/request is that, if the name of module and a 
 variable/constant/struct/class/template/enum that is in that 
 module matches each other exactly, as seen in the example 
 above, without name duplication, access should be passed to 
 that variable/con... etc.

 Currently, by using package.d, this is supported in "made up" 
 way by putting programmer into duplication again while using 
 directories, but for module itself, I do not see any solution 
 currently.

 Currently, I couldn't have found any issue about adding this 
 feature. So is the proposal.

 module my.big.lib.createFile;

 void createFile( string fname ){}

 Somewhere else in the code universe:

 my.big.lib.createLib("FSociety.dat");
Currently there are two problems about adding this feature: 1. If a class will be defined in the module that's name is same as class, then, as class names are PascalCase, module name should be made PascalCase as well, which is not used in Phobos, but at least do not prevent other people to access a feature just because Phobos is designed in that way. 2. If there will be two different classes in the module with one of them named same with the module and other is different, proposed method prevents being able to access the other class. (Same problem for variables, consts, etc.)
Dec 25 2015