D's hidden function calls getting crazier.

Hors ho at rs.com
Fri Oct 27 17:30:34 UTC 2023


On Friday, 27 October 2023 at 14:18:45 UTC, Dom DiSc wrote:
> On Friday, 27 October 2023 at 13:37:14 UTC, Hors wrote:
>> ```d
>> str.toLower
>> ```
>> calls toLower function which makes a new string every time you 
>> use it. So it's incorrect to tell everything can be solved 
>> with inline functions
>
> I would recommend to ALWAYS assume that everything is a 
> function call. Because having direct access to object members 
> is a very rare case, and very bad design for a public interface 
> of a library.
> So it will only happen in code written by yourself. And then, 
> if you don't like UFCS, don't use it.
>
> UFCS is a huge advantage for reading algorithms in order 
> instead of using lots of parantheses if you want to chain 
> something.
>
> ```d
> a(b(c(d(e(f()))),5));
> ```
>
> which is pretty unreadable will become
>
> ```d
> f.e.d.c.b(5).a;
> ```
>
> which is shorter, more readable and calling order as well as 
> the receiver of additional parameters is now obvious.
>
> UFCS is one of D's major boons. If you work with it for a 
> while, you will start to hate other languages that don't 
> provide it.

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?


More information about the Digitalmars-d mailing list