Import concerns revisited
Dave
Dave_member at pathlink.com
Sun Jul 9 15:31:40 PDT 2006
Sean Kelly wrote:
> Dave wrote:
>> John Reimer wrote:
>>> In article <e8qjkf$2tqc$1 at digitaldaemon.com>, Walter Bright says...
>>>> Ivan Senji wrote:
>>>>> Sure I could use
>>>>>
>>>>> static import m2;
>>>>> alias m2.func f2;
>>>>>
>>>>> And that would be an improvement but it is still longer (and arguably
>>>>> less understandable) than:
>>>>>
>>>>> import m2.func as f2; ;) :)
>>>> Let's say you're going to do more than one:
>>>>
>>>> static import m2;
>>>> alias m2.func f2;
>>>> alias m2.abcd f3;
>>>> alias m2.efgh f4;
>>>>
>>>> vs:
>>>>
>>>> import m2.func as f2;
>>>> import m2.abcd as f3;
>>>> import m2.efgh as f4;
>>>>
>>>> Not much of a difference. I'm also not understanding why alias is
>>>> hard to understand.
>>>
>>> Well, your example is just showing selective renaming from /one/ module.
>>> Naturally these two are going to be very similar. Please look at Kris'
>>> suggestion, thoroughly. The whole system is vastly superior once one
>>> starts
>>> referencing selective importing from multiple modules. The total
>>> number of
>>> lines are cut in half verses using static import and alias.
>>>
>>> Also, for selective import, I think using "from" instead of "with"
>>> looks much
>>> better.
>>
>> I agree that 'from' is better than 'with', but I just don't see the
>> advantage of
>>
>> from m2 import func,abcd,efgh;
>>
>> over the likes of
>>
>> import m2.func, m2.abcd, m2.efgh as f4;
>> import std.stdio, this.other.cool.db.lib as dblib;
>>
>> because then you get the aliasing in there as well. True, there's a
>> little redundant typing of 'm2'.
>
> If 'm2' is actually 'some.guys.super.cool.library.module' then the
> redundant typing adds up.
But then you could alias some.guys.super.cool.library.module, er, no
wait... <g>
Seriously, you're spot on - I didn't consider that.
>
>> Also,
>>
>> from m2 private import func,abcd,efgh;
>>
>> or
>>
>> private from m2 import func,abcd,efgh;
>>
>> sucks IMO.
>
> I don't really mind the former, and I wouldn't terribly mind the latter
> if expressed differently:
>
> private
> {
> from m2 import func, abcd, efgh;
> }
>
> Though I think the real utility with the from/with syntax is that it
> would allow for selective public exposure of symbols to importing modules.
>
>
> Sean
More information about the Digitalmars-d
mailing list