Rethink OOP access permissions
Daniel N
no at public.email
Sun Apr 28 13:05:30 UTC 2024
On Saturday, 27 April 2024 at 12:37:14 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> 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).
>
You're right, it's not easy, but it could be simplified using
bitfields instead of enums.
More information about the dip.ideas
mailing list