I've just fixed UFCS for the experimental type function branch
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Sep 10 16:52:12 UTC 2020
On Thu, Sep 10, 2020 at 04:28:46PM +0000, Bruce Carneal via Digitalmars-d wrote:
> On Thursday, 10 September 2020 at 15:14:00 UTC, Per Nordlöw wrote:
> > On Thursday, 10 September 2020 at 09:43:34 UTC, Stefan Koch wrote:
> > > limited UFCS for type functions works again.
> > Having type functions with UFCS is a significant improvement of the
> > developer experience aswell compared to having to use templates.
> Absolutely. Functions are more readable, compose more readily, are
> easier to debug (better locality), and tickle fewer compiler problems
> than templates. CTFE is a huge win overall, "it just works".
I wouldn't be so sure about that last part. The current CTFE
implementation is, shall we say, hackish at best? It "works" by
operating on AST nodes as if they were values, and is slow, memory
inefficient, and when there are problems, it's a nightmare to debug. For
small bits of code, it works wonderfully, but it's not at all scalable:
try some non-trivial CTFE and pretty soon your compile times will be
skyrocketing, if the compiler manages to finish its job at all before
being killed by the kernel OOM killer for gobbling too much memory. (Of
course, templates, esp. the recursive kind, are mostly to blame for
this, but CTFE isn't exactly an innocent bystander when it comes to
> By contrast, when using D's pattern matching meta programming
> sub-language, things start out very nicely but rapidly progress to "it
> probably works, but you'll have a devil of a time debugging it if it
> actually doesn't, and you may not know that it doesn't for a few
> years, best of luck".
To be fair, the problems really only arise with IFTI and a few other
isolated places in D's template system. In other respects, D templates
are wonderfully nice to work with. Definitely a refreshing change from
the horror show that is C++ templates.
> In a type function world we'll still need templates, we'll just need
> fewer of them.
Generally, I'm in favor of this. Templates have their place, but in many
type manipulation operations, type functions are definitely better than
truckloads of recursive template instantiations with their associated
memory hoggage and slowdown of compile times.
English has the lovely word "defenestrate", meaning "to execute by throwing someone out a window", or more recently "to remove Windows from a computer and replace it with something useful". :-) -- John Cowan
More information about the Digitalmars-d