Why is D unpopular

bauss jj_1337 at live.dk
Mon Jun 13 09:27:42 UTC 2022


On Monday, 13 June 2022 at 09:05:43 UTC, Mike Parker wrote:
>
> I don't get why you expect it to work. If you declare `Bar` 
> outside of the module, then how could you access the private 
> members of `Foo` through a `Bar`? It works in the same module 
> because... private to the module.

Because Bar inherits from Foo, Foo is in a, thus it should be as 
following:

Outside of the module Foo resides in:

- Only public members are accessible.

Inside the module Foo resides in:

- All members are accessible.

That's the whole point of module private, that you can access 
private members within a module regardless of where they reside, 
as long as you're in the module the symbol belongs to.

In this case _c belongs to the module a, so we should always be 
able to access _c within the module.

If D wasn't module private, then I wouldn't expect it to work, 
but since D states itself to be module private then I expect it 
to work because:

Bar inherits Foo, _c is a member of Foo, but also private to the 
module of Foo.

When we access Bar within the module of Foo, then all members of 
Foo should be accessible.

When we access Bar outside of the Foo's module, then only public 
members of Foo should be accessible.

This should always be true with module private, it wouldn't be 
true with class private.

So either D needs to admit it's not truly module private or it 
needs to fix that.


More information about the Digitalmars-d mailing list