Very hacky solution to class private members

Dom Disc dominikus at scherkl.de
Thu Jun 9 11:04:31 UTC 2022


On Thursday, 9 June 2022 at 10:40:01 UTC, bauss wrote:

> Might as well just make everything public then, right?
No. I have written reducing the search-space to one file *DOES* 
reduce the effort.
But reducing it to a part of a file (which class level privacy 
would do) does not, because still all member-functions that 
shouldn't have access to the privates still have to be reviewed. 
You still have to search the whole file to find all usages of 
private variables, so you gain nothing.

> Why stop there. Removing private, protected, package etc. is 
> the way to go then?
Nonsense. Nobody wants that.

> the point of it all is to cut down the amount of code you have 
> to review.
Yup. And the reduction gained by class level in addition to 
module level (which is not available in C++) is neglictable.

> There's no reason to do the analysis yourself if the compiler 
> can do it for you in 99% of the cases.
But it can't. You have to check the member functions manually 
anyway.
On module level you have to additionally check the handful of 
function that are also in the same file. But in C++ instead you 
have to check the additionally friends, which may be scattered 
all over the whole project.

So in comparison with C++ module level privacy is just better (if 
you don't put everything in one file).
Within D alone, we would gain nearly nothing by an additional 
level.



More information about the Digitalmars-d mailing list