Lawrence Aberba

Authored Comments

Hey Arthur, UFCS helps avoid writing code like: finish(make(bake(1,4)));

In D you can write it as: bake(1,2).make(). finish () OR more idiomatically, 1.bake(3).make.finish. So it reads in the order you'd process it in your mind when reading the code.

Any other extra argument gets written like 1.call(2,3,4,5,...). of course if using UFCS makes sense only in that particular context.

UFCS is actually just a syntax trick. It comes at no extra performance cost. The D compiler rewrites it to normal styling during compilation. But for the programmer, UFCS just beautifies your code. So its more lightweight compared to using a class. Sometimes people write classes to get a similar feel but with D UFCS gives you that experience. UFCS is not built into the types, its just a syntactic sugar.

I'm not familiar with .Net extensions. However with D, the compiler rewrites it like how you'd normal call it. So it's a convenient syntax for the programmer.

So 1.add(2): gets rewritten to add(2,2) during compilation.