Rethink OOP access permissions
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Sat Apr 27 12:37:14 UTC 2024
On 27/04/2024 9:25 PM, Daniel N wrote:
> 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;
> }
> ```
While I'm not against it, think about how this would be implemented.
You would need an enum with all the different values for both getting
and setting, I can already see some resistance there.
Plus you'd need some arithmetic on the values, to see if you can perform
operators (modify in place).
> Some ideas from C# are also interesting. They have 'init' and 'readonly'
> aswell.
The C# ``readonly`` type qualifier is similar to our ``immutable``, this
comes from Midori and one of the language authors Joe Duffy has compared
it equivalently against D's previously.
More information about the dip.ideas
mailing list