private(this) vs LINT

The Zealot zod at zod.zod
Thu Jun 30 14:55:47 UTC 2022


On Thursday, 30 June 2022 at 11:37:30 UTC, bauss wrote:
> On Thursday, 30 June 2022 at 11:36:01 UTC, The Zealot wrote:
>> On Tuesday, 28 June 2022 at 22:03:54 UTC, forkit wrote:
>>> On Tuesday, 28 June 2022 at 20:58:56 UTC, Daniel N wrote:
>>>>
>>> Without something like private(this), hazardous interactions 
>>> are inevitable, and will increase with scale (e.g. having 20+ 
>>> friend functions in your class ;-)
>>
>> this is just not true. don't put the damm class in module 
>> scope if you don't want it accessible.
>>
>
> Don't put @nogc, just stop GC allocations yourself.

you can do that without @nogc ;) don't link in the GC.
But my point is you _should not_ put the class in module scope in 
the first place, it doen't belong there. if it has private parts, 
it is an implementation detail and should not be visible at all, 
but an _interface_ should be used. and if you need inheritance, 
it _should_ be placed in it's own module.

e.g.
```
interface Foo {
}
Foo fn() {
    static class Bar : Foo { int private_x; } // private_x access 
is limited to fn() scope
    return new Bar ();
}
```





More information about the Digitalmars-d mailing list