[Feature Request] Single name access when module name and content are same

tcak via Digitalmars-d digitalmars-d at puremagic.com
Fri Dec 25 09:21:01 PST 2015


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.)


More information about the Digitalmars-d mailing list