Very hacky solution to class private members

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Thu Jun 9 10:59:12 UTC 2022


On Thursday, 9 June 2022 at 10:39:17 UTC, Dom Disc wrote:
> Whatever you do, it needs to be something human-readable, 
> because the compiler can't help you there.

Yes, although for C++ private + friend is helpful. I actually 
would want friend in C++ to be more limiting, so that you could 
say "this function is allowed to call this member, but nothing 
else". Mostly relevant for concurrency issues, could be useful in 
that context as finding such bugs is extremely time consuming.

Tighter encapsulation is valuable when you change/restructure 
your codebase, but it equally important to have clean syntax that 
is easy to read!

> If something is convoluted, you need to sort it out and split 
> into two modules. Another protection level won't help.

I would not want to write such convoluted modules, but maybe 
others do.

> Because, as I said, a new level won't reduce your effort to 
> understand whats happening, you still need to inspect 
> everything within the file. But splitting would help a lot with 
> that.

You don't have to inspect everything in the file. For instance, 
in C++ I often let an inner class (class within a class) be 
protected against methods in the outer class.

Also, in Simula a class and module was the same construct. A 
class was used to represent what D uses a module for.

>> If someone ever started on D3, that is the place to start IMO.
>
> Sorting things out should be possible without need for an new 
> fork. It should be done withing the actual phobos as it 
> wouldn't change the interface (at least not much).

So this is my perspective:

Phobos is one of those «larger» codebases where people have made 
an effort to use D constructs to write «good» code to the best of 
their ability. We cannot expect better for the average D 
programmer. So that is a realistic picture of what D code over 
time will look like.

As such, one can study it to figure out where the language has 
room for improvement. You could also improve on Phobos, but that 
is less important (if it works).




More information about the Digitalmars-d mailing list