May 14 Four draft:Third draft: Turn properties into first class accessors | ||||
---|---|---|---|---|
| ||||
I had remove the array index section as I couldn't find anything that is similar to what I am proposing in c# language. The one that I had found is the array index to the class object itself and not as part of the member variable/function itself, so that concept is definitely out of the scope here. I had done a basic rewrite to better explain the code rewrite. https://github.com/12345swordy/Public-Documents/commit/bf67cd7c77f953d752afc532dd43543b0d9be716 - Alex |
May 16 Re: Four draft:Third draft: Turn properties into first class accessors | ||||
---|---|---|---|---|
| ||||
Posted in reply to 12345swordy | On 15/05/2025 3:29 AM, 12345swordy wrote:
> I had remove the array index section as I couldn't find anything that is similar to what I am proposing in c# language. The one that I had found is the array index to the class object itself and not as part of the member variable/function itself, so that concept is definitely out of the scope here.
> I had done a basic rewrite to better explain the code rewrite.
>
> https://github.com/12345swordy/Public-Documents/commit/ bf67cd7c77f953d752afc532dd43543b0d9be716
>
>
>
> - Alex
I'm a little concerned about how the @property function arguments are working.
1. ``inout`` is legal on parameters ``void func(inout int);`` compiles. It utilizes the storage class to mean something other than "conditional const".
2. Following from 1, what if you wanted a parameter to just accept an int, I will note in your example it is by-value, not by-ref, where assignment is irrelevant.
3. Instead of splitting one parameter into two with the same name (breaks assumptions of one parameter per name, except for variadic), lower it to a struct which has two fields. This also solves for templates via use of ``alias this``.
4. You still need a way to request and handle the overload resolution for the property pair, I suggest using ``@property`` on the parameter to do so. However this may have ambiguity to the Type parameter, so another attribute may need to be used if it is offered.
i.e. a potential lowering:
```d
struct __PropertyPair(Getter, Setter) {
Getter getter;
Setter setter;
alias getter this;
void opAssign(T)(T value) {
setter(value);
}
}
```
|
Copyright © 1999-2021 by the D Language Foundation