new DIP14: Package import path association

Jacob Carlborg doob at me.com
Tue Oct 18 05:26:36 PDT 2011


On 2011-10-18 13:48, Martin Nowak wrote:
> On Tue, 18 Oct 2011 13:23:02 +0200, Jacob Carlborg <doob at me.com> wrote:
>
>> On 2011-10-18 09:38, Martin Nowak wrote:
>>> http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP14
>>
>> What happens if you import a the same file twice using different
>> paths, i.e. relative and absolute path?
>>
>> Will the imported files need a module declaration or will the compiler
>> just care about the path?
>>
>
> The module name is determined by the module declaration or implicitly by
> the basename of the file.
> Module collisions are already detected based on the module name.
> You can actually import two identical modules through different
> files/symlinks as long
> as they don't have a module declaration.
> This does not differ from the current behavior.
>
> martin

What happens then, to module constructors and similar? What concerns me 
is that something similar to Ruby 1.8 could happen.

In Ruby when the compiler encounters a "require" it will load the file 
specified in the require call. Meaning any top level code will be 
executed. If you require the same file again, i.e. from another file it 
will not execute the required file again because it's already loaded.

The problem with this is that the load path which stores all loaded ruby 
files does not sore the full path name of a ruby file, it stores what 
every you called "require" with.

If you then require the same file using two different paths, i.e. 
relative and full path, the required file will be executed again, 
possibly resulting in warnings like:

warning: already initialized constant FOO

This is fixed in Ruby 1.9 by always storing full paths to required files 
in the load path.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list