Feedback for generics prototype

Firstly, it’s worth noting that templates in C++ are very different from the generics being proposed here. Templates are kind of like compiler-assisted copy-pasting which can lead to very difficult to understand error messages and requires the compiler to expand the templates first before it’s able to check if their use is valid (which is partly what contributes to the previous problem). The generics being proposed here are more like traits, concepts, or interfaces where the onus is on the developer to specify what actions the type must be able to perform and the compiler can check the validity of the generic early in the compilation process with much more useful error messages.

Secondly, his issue with templates is to do with compilation performance, not runtime performance. While that’s a valid reason for certain code bases to avoid heavy generic use, I don’t think it’s a valid reason to not implement it in a language considering the benefits it brings. In fact it actually brings benefits to runtime performance when compared to the current alternative (class polymorphism).

Operator overloading is probably off-topic for this thread, but I think it’s worth noting that Fortran already has operator overloading (and again his issue is with comprehensibility of operator overloading, not performance).

5 Likes