Rethink OOP access permissions
Daniel N
no at public.email
Sat Apr 27 09:25:13 UTC 2024
This is an alternative to "private(this)".
I think it would be much more interesting if it was possible to
separate read and write permissions instead.
(The syntax is just an example, not that important, just for
illustration purposes.)
```d
class C
{
get(module) set(class) int x = 0;
}
```
Some ideas from C# are also interesting. They have 'init' and
'readonly' aswell.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/init
```d
struct Point
{
public int X { get; init; }
public int Y { get; init; }
public readonly int Z { get; init; }
}
```
Instead of trying to cater to a single usecase ("private(this)").
We could get unix like access permissions instead? Some
additional benefits would be fast access to read-only variables
instead of an expensive function call.
More information about the dip.ideas
mailing list