Import concerns revisited
Ivan Senji
ivan.senji_REMOVE_ at _THIS__gmail.com
Sun Jul 9 01:41:30 PDT 2006
Walter Bright wrote:
> kris wrote:
>> // import as we know it today, and with a required prefix "locale."
>> import lib.text.locale;
>> import lib.text.locale as locale;
>>
>> // selective import of one entity, and alternatively with an alias
>> import lib.text.locale.Time;
>> import lib.text.locale.Time as otherTime;
>>
>> ==================================
>
> But those *are* aliases. It's just using a different keyword, "as"
> instead of "alias", and a slightly rearranged syntax. So what's the
> difference between:
>
> import lib.text.locale.Time as otherTime;
>
> and:
>
> alias lib.text.locale.Time otherTime;
>
> ? Absolutely none, unless I am totally misunderstanding your proposal.
There should be a big difference (if I understand things correctly):
A simple example:
If I have:
module m1;
int func(){return 1;}
and
module mainmodule;
import m1;
void main()
{
writefln(func());
writefln(m1.func());
}
there are no problems with that!
But if I add:
module m2;
int func(){return 2;}
and change mainmodule to:
import m1;
import m2;
void main()
{
writefln(func()); //<- conflict
writefln(m1.func());
writefln(m2.func());
}
And suddenly I get a lot of conflicts.
Sure there is a way to solve it by adding:
alias m1.func func;
And then use m2.func to use func from m2.
But what if I wanted to give m2.func a totally different name to avoid
confusion, i can try to add this:
alias m2.func someOtherName; instead of alias m1.func func;
But then once again I would get an error about a conflict:
Once again there is a solution:
alias m1.func func;
alias m2.func f2;
And it works OK, but the intention here is a bit hidden.
Conclusion:
import m2.func as f2;
is not the same as:
import m2;
alias m2.func f2;
but is equivalent to:
import m2;
alias m2.func f2;
//insert here a possibly huge number of aliases to avoid conflicts of
m2.func with func from other imported modules.
More information about the Digitalmars-d
mailing list