Why is D unpopular

Max Samukha maxsamukha at gmail.com
Mon Jun 13 20:05:47 UTC 2022


On Monday, 13 June 2022 at 17:08:55 UTC, Ali Çehreli wrote:

>
> Access control is just an aspect of OOP. Neither friend nor 
> module-level private breaks OOP. Being a simpleton, I start 
> reading from Wikipedia but others can read their trusted OOP 
> gospel to gather the same information:
>
>   
> https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)
>
> For example:
>
>   "Under the definition that encapsulation "can be used to hide 
> data members and member functions", the internal representation 
> of an object is generally hidden from view outside of the 
> object's definition."
>
> Note "can be used to hide" and "generally hidden". See, all the 
> other languages apply their view of 'private', not OOP's view 
> of 'private'.
>
> I find D's 'private' very useful and I doubt a single project 
> had any problem with it.
>
> Ali

I am not debating its usefulness, but it would be even more 
useful if it meant what I believe most programmers not damaged by 
Simula or Pascal intuitively expect, that is, 'private to the 
parent scope'. And then we could have something like 
'private(ancestor)' (or extend 'package(ancestor')) for 
specifying the desired boundary of encapsulation.

Currently I just cannot enforce class invariants (without 
isolating the class in its own module). See this gospel:

"Encapsulation also protects the integrity of the component, by 
preventing users from setting the internal data of the component 
into an invalid or inconsistent state." 
(https://en.wikipedia.org/wiki/Information_hiding#Encapsulation)



More information about the Digitalmars-d mailing list