D's hidden function calls getting crazier.

Dom DiSc dominikus at scherkl.de
Fri Oct 27 14:18:45 UTC 2023


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.



More information about the Digitalmars-d mailing list