imports - 2 years later

Derek Parnell derek at psych.ward
Thu Mar 9 12:46:17 PST 2006


On Fri, 10 Mar 2006 04:40:15 +1100, Ant <Ant_member at pathlink.com> wrote:

> In article <dupl7t$mqk$1 at digitaldaemon.com>, Lars Ivar Igesund says...
>>
>> Derek Parnell wrote:
>>
>>> On Fri, 10 Mar 2006 00:28:50 +1100, Ant <Ant_member at pathlink.com>  
>>> wrote:
>>>
>>>> In article <ops5425bcg23k2f5 at nrage.netwin.co.nz>, Regan Heath says...
>>>>>
>>>>> I believe Walter discourages the use of import inside a class and I
>>>>> believe your use of them is the reason for the problem.
>>>>
>>>> I need to make a joke and a note:
>>>>
>>>> so we have a ternary logic:
>>>> - import in module: true
>>>> - import in function: false
>>>> - import in class: maybe
>>>
>>> Why would one think of importing stuff into a class? I don't get it.  
>>> Are
>>> you trying to make the imported stuff 'local' to the class members and
>>> nothing else?
>>>
>>
>> Because when Ant first wrote DUI, class local imports were a workaround  
>> to
>> much bigger import problems than those we meet today.
>
> yes, and more,
> I'm going to use the import symbols inside the class body,
> what makes no sence is to have the import at the module level - see there
> is always another way to look at things.
>
> and more,
> If I have multiple classes in the same module maybe it makes sence to
> import the specific modules to the right class.

But this is the part I don't get. In my opinion, it does make sense to  
import at the module level, because in D everything in the same module is  
accessible. Multiple classes in the same module *means* that they are  
friends and thus can access each other's internals. So importing at the  
class level can not restrict access between classes residing in the same  
module. If you really must have restricted access you must also split the  
classes into different modules.

> Anyway, this needs to be reviewd.
>
> And import in classes should either be corrected (please) or made  
> illegal(no).

Yes, this does need reviewing and clarificaton. I imagine that the  
simplest 'correction' would be to that if an import is found inside an  
aggregate (class or struct) then just assume it to be at the module level.

To improve the access granularity, we would need a new scoping keyword  
(e.g. 'local') in order to sign those members that are only accessible  
 from within the same class/struct.

-- 
Derek Parnell
Melbourne, Australia



More information about the Digitalmars-d-bugs mailing list