[OT] my experience with nullable types (C#)
user1234
user1234 at 12.de
Wed May 7 13:56:12 UTC 2025
On Wednesday, 7 May 2025 at 07:32:17 UTC, user1234 wrote:
> On Wednesday, 7 May 2025 at 07:08:43 UTC, Python wrote:
>> BTW, NET10 will have a new operator, the null check assignment:
>>
>>
>> `someRef?.Prop = 10` will be shorthand for:
>>
>> ```
>> if (someRef != null)
>> someRef.Prop = 10;
>> ```
>
> Curious, I'd rather would have implemented that using an hidden
> alloca:
>
> ```
> PropType __tmp;
> (someRef ? someRef.Prop : __tmp) = 10;
> ```
>
> Actually having `?.` implemented to yield a hidden value when
> the LHS evaluates to false would have made the assignment case
> already working since years.
Forgot to say: this design may lead to think "the compiler will
generate a useless alloca + assignment". Indeed, but dont forget
that optimizing compilers are good at droping these ;)
That's how it's implemented in styx. But prior to that the
concept was proved with a D template, that is still used in
D-Scanner codebase I believe.
More information about the Digitalmars-d
mailing list