D's hidden function calls getting crazier.

Timon Gehr timon.gehr at gmx.ch
Sat Oct 28 14:27:24 UTC 2023


On 10/27/23 14:38, Hors wrote:
> It's impossible to tell if reading or writing an object's variable would 
> call a function because of UFCS or @property. it just hurts because you 
> can't know if it's a function call without looking at implementation.
> 
> The most basic example is
> ```
> obj.val = 1; // actually calls obj.setVal(1)
> assert(obj.val == 1); // actually calls obj.getVal(), assertion may fail 
> if getVal or setVal is not implemented correctly. Which is unexpected
> ```
> ...

I guess you can write `*&obj.val = 1;` to make sure it is a field.

> To fix this hidden function craziness, UFCS needs to require 
> parantheses, and property function needs to be removed entirely.

No. Abstractions are valuable. Being able to add (and remove) e.g., 
logging code after the fact onto an existing exposed public field is 
very useful.



More information about the Digitalmars-d mailing list