Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> D has a more unusual take on private fields. Private fields prevent access by other modules, but do not prevent access from within the same module. The module is really the unit of encapsulation, not the struct.

Other languages would call these "internal", not "private".



Rust uses "private" to express the same notion, that a field can be accessed from the defining module and its submodules, but not from any other modules, unless you explicitly add a visibility modifier like "pub" or "pub(crate)".


Well, OOP was used, and its naming conventions settled, decades before Rust or D came along. See https://en.wikipedia.org/wiki/Simula for example. They decided to go against established conventions (as far as I understand - I don't know what the relationship between Rust modules and classes is). That's fine, but let's not pretend otherwise.


A Rust module is similar to a Java package or a C# namespace.

Java calls this notion "package-private" [0], at least in some of its documentation. Delphi calls this notion "private" [1], and has a separate "strict private" for members only visible from the containing class.

Also, C# uses "internal" to refer to a different notion, that the type or member can be accessed from anywhere in the containing assembly, not just the containing namespace [2]. (In D this is "package", and in Rust this is "pub(crate)".)

I'm just trying to push back on treating "other languages" as a unified whole here.

[0] https://docs.oracle.com/javase/tutorial/java/javaOO/accessco...

[1] https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Clas...

[2] https://learn.microsoft.com/en-us/dotnet/csharp/programming-...




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: