Code That Says Exactly What It Means

ealot zealot at planet.earth
Thu Oct 30 22:27:32 UTC 2025


On Thursday, 30 October 2025 at 21:49:45 UTC, Peter C wrote:
> On Thursday, 30 October 2025 at 13:31:48 UTC, Zealot wrote:
>>     [...]
>
> Thanks for raising the discussion ;-)
>
> I think I might be missing your point though (i.e. the code 
> below works just fine):
>
> // ===============
>
> module foo;
> @safe:
> private:
>
> import std;
>
> public class A
> {
>     scopeprivate int p = 1;
>     private int a = 42;
>     protected  int b = 43;
>     int c = 44;
> }
>
> // ===============
>
> module bar;
> @safe:
> private:
>
> import std;
> import foo;
>
> void main()
> {
>     auto a = new A;
>
>     static foreach(i; 0..a.tupleof.length)
>     {
>         writeln(__traits(getVisibility, a.tupleof[i]), " => ", 
> a.tupleof[i]);
>     }
> }
>
> // ===============
>
> scopeprivate => 1
> private => 42
> protected => 43
> public => 44

a) tupleof ignores the privacy attributes. tupleof allows you to 
access private state.
b) any code that exists and uses getVisibility now has a new case 
introduced which it doesn't handle, so you would break all that 
code by introducing scopeprivate.


More information about the Digitalmars-d mailing list