Preparing for the New DIP Process

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Jan 22 23:28:40 UTC 2024


On Monday, January 22, 2024 4:01:54 PM MST Walter Bright via Digitalmars-d-
announce wrote:
> On 1/21/2024 3:51 AM, zjh wrote:
> > When you need `friend`, You can put them all in one module.
> > Sometimes, when `multiple classes` are closely related and independent,
> > `class level privacy` becomes very important. No one wants , someone from
> > outside may secretly steal money from your home.
>
> D does not allow a different module accessing private class members. Private
> access is limited to the module enclosing that class.
>
> This encourages a different use of modules than C++ "toss code randomly into
> different source files."

It also greatly simplifies having to deal with visibility attributes. I can
understand folks being concerned about it at first, but in practice, it
really isn't a problem.

If it really is a problem for a piece of code to have access to something
private that's in the same module, then you can simply put them in separate
modules, and if your module is large enough that you can't keep track of
that sort of thing like you need to, then it should probably be split up.

And for those cases where you need cross-module access without it being
public, there's always the package attribute.

The end result is that visibility attributes are very easy to reason about,
and you don't have to worry about them much. I really think that the folks
who insist on having private be private to the class/struct (or who insist
on a new attribute which does that) are just too tied to how other languages
work and haven't given D's approach a chance. I don't think that I have
_ever_ seen a problem stem from the fact that D's private is private to the
module. And in fact, it causes so few issues that way that plenty of folks
end up being surprised to find out that it works that way, because they've
never run into a situation where it actually mattered that it wasn't private
to the class/struct.

Of course, ultimately, different programmers have different preferences, and
none of us are going to be happy about everything in any language. So, of
course, there are going to be some folks who are unhappy with how D defines
private, but it's not a feature that has actually been causing us problems,
and it really doesn't make sense at this point to change how it works.

- Jonathan M Davis





More information about the Digitalmars-d-announce mailing list