[OT] What are D's values?

bauss jj_1337 at live.dk
Wed Oct 6 22:14:32 UTC 2021


On Wednesday, 6 October 2021 at 15:59:46 UTC, Steven 
Schveighoffer wrote:
> On 10/4/21 6:15 PM, Walter Bright wrote:
>
>> This is plasticity, the opposite of brittleness.
>> 
>> What are your experiences with this?
>
> For the most part, it's great!
>
> There is one place where I have struggled though, and D might 
> be able to do better. And that is with optional parentheses and 
> taking the address. When a property can be either an accessor 
> or a field, then `obj.prop` can work the same. However, 
> `&obj.prop` is not the same.
>
> I have solved it by using this stupid function:
>
> ```d
> auto ref eval(T)(auto ref T t) { return t; }
>
> // instead of &obj.prop
> auto ptr = &eval(obj.prop);
> ```
>
> I just came across this workaround in my code and since I wrote 
> it a long time ago it puzzled me "what is this `eval` 
> function?". Took me a minute to remember why I did that.
>
> While it's nice D has a mechanism to work around this 
> difference, I find having to use such shims a bit awkward. And 
> it's a direct consequence of hiding the implementation of a 
> field/property behind the same syntax. You can find other cases 
> where D can be awkward (such as `typeof(obj.prop)` or checking 
> types regardless of mutability).
>
> What is the "better" answer though? I don't know.
>
> -Steve

This is something I agree with. I often come across small 
snippets of code that I've made and I sometimes can't remember 
why I did something like it, until I try it and then it's like 
"oh yeah it was to work around this thing"


More information about the Digitalmars-d mailing list