packageless modules == pure evil?

Bill Baxter dnewsgroup at billbaxter.com
Sun Feb 17 15:25:15 PST 2008


torhu wrote:
> Bill Baxter wrote:
>> I would just like to confirm with others that this is the case, and 
>> also perhaps raise general awareness about the issue.
>>
>> The issue is that modules without a package will conflict with a 
>> similarly named module in _any_ package.
>>
>> So for example if there's a module called "foo" and you import it in 
>> your project, then your project absolutely CANNOT have another module 
>> named "foo" or "blarf.foo" or /anything/ that ends in ".foo" anywhere 
>> in the import chain.
>>
>> For this reason it must be concluded that packageless modules are pure 
>> evil, and should never ever be used.  Always always give your modules 
>> a package even if it's just repeating the module name like "foo.foo".
>>
>> Am I right about this?
> 
> What kind of conflict do you mean?  Compiler errors or linker errors? 
> The only linking problem I've seen is that if you have two modules with 
> the same name, the compiler will overwrite one with the other, so only 
> one of them gets linked in.  I guess the -op switch to bud or the 
> compiler will fix this.  dsss avoids this issue by default, as long as 
> you don't have two modules of the same name and both are packageless.
> 
> I've come across this issue maybe once, and then I just renamed one of 
> the files to fix it.

The problem that prompted this message was that I had a module called 
just "blas" in one place and was trying to make another module called 
"dflat.blas".  But that breaks plain "import blas".  It picks up the 
"dflat.blas" rather than the packageless blas, even though I didn't 
specify that I wanted "dflat.blas".

>> (and anyone know if module "foo.bar" will clash with "baz.foo"?)
> 
> Tango has packages and modules with the same name, so it should work.

But the top-level package may be special.  I don't think there's a 
module called "tango" in Tango, is there?

--bb


More information about the Digitalmars-d-learn mailing list