Annoying module name / typename conflict

bearophile bearophileHUGS at lycos.com
Mon Apr 2 15:20:11 PDT 2012


H. S. Teoh:

> Is there any reason whatsoever that the compiler should resolve 
> "S" to
> the module rather than the struct defined by the eponymous 
> module?

For DMD choosing one or the other is arbitrary. It's a defect of 
the way the D module system is designed. This problem is _absent_ 
in the Python module system.

Maybe one way to reduce a bit this pain source in the D module 
system is to forbid name clashes, this means the compiler 
statically forbids a module "foo" to contain the name "foo".


> Given that in D, private applies per module, it's quite often 
> desirable
> to name the module after the single class/struct that it 
> defines.
> However, this name conflict makes this scheme rather painful to 
> use. :-(

In D it's better to give them different names. Like a class "Set" 
is better to go in a module named "sets".

Bye,
bearophile


More information about the Digitalmars-d mailing list