D's hidden function calls getting crazier.

Dom DiSc dominikus at scherkl.de
Sat Oct 28 00:12:29 UTC 2023


On Friday, 27 October 2023 at 17:30:34 UTC, Hors wrote:
> I love UFCS as it makes easier to chain functions. But I have 
> some little worries about confusing variables with functions, 
> and I can't understand what is bad about using variables for a 
> public interface, do we really need a getter and setter 
> functions instead of variables?

It depends. If you have a pure data-type, variables (fields) are 
ok.
But in an object (class) normally I'd rather nobody messes with 
the internal stuff. Its just too likely to botch things up. So, 
yes, in a library I prefer getters (setters not so much for the 
same reason).
But setters are still better than variables, as they don't allow 
to take the address of the field controlled by them.

Of course nothing can stop you from shooting yourself in the foot 
if you really try - but it should not be the first and easiest 
thing to do.


More information about the Digitalmars-d mailing list