Code That Says Exactly What It Means
Peter C
peterc at gmail.com
Thu Oct 30 21:49:45 UTC 2025
On Thursday, 30 October 2025 at 13:31:48 UTC, Zealot wrote:
> On Thursday, 30 October 2025 at 06:21:41 UTC, Peter C wrote:
>> But I am genuinely open to listening to a good, rational
>> argument, make no mistake about that.
>
>
> you ignore the amount of code adding scopeprivate would affect.
> for example any code that uses __traits getVisibility would be
> likely broken by introducing a new case.
>
> metaprogramming also would have new weird special cases.
>
> funnily tupleof would keep working (because it's arguably
> broken now); protection doesn't work the way you think it does
> anyway, consider this:
> ```d
>
> --- foo.d
> module foo;
> import std;
>
> class A {
> private int a = 42;
> protected int b = 43;
> int c = 44;
> }
>
> --- bar.d
> 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]);
> }
> }
>
> ```
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
More information about the Digitalmars-d
mailing list