3 ms·
Haven't used them much (or C++'s at all), but (not speaking as a PL-designer-or-implementer), D's templates seem to be not bad. I could understand how to use th
by vram22 8y ago
Haven't used them much (or C++'s at all), but (not speaking as a PL-designer-or-implementer), D's templates seem to be not bad. I could understand how to use them for some simple cases, at least, without much studying of the subject.
And I liked what Walter Bright (D creator) said in (IIRC, in a DDJ article): something to the effect that, after working on the design of D templates for a while, a sudden insight he had, was that templates were (just [1]) a way of parameterizing a function not just by value parameters, but by type parameters too.
[1] Not really "just", of course - there will be a lot to the implementation, but conceptually, that simple.
Edit: Links:
https://dlang.org/spec/template.html https://dlang.org/spec/template.html
https://tour.dlang.org/tour/en/basics/templates https://tour.dlang.org/tour/en/basics/templates
https://dlang.org/articles/templates-revisited.html https://dlang.org/articles/templates-revisited.html
- zamalek 8y ago> Not really "just", of course For C++. Tons of languages do the type paramaterization and it solves more than 80% of the common problems. 80% of the remaining 20% can probably be covered with compile-time code generation (or runtime code generation), for which templates aren't the only solution (D, C# and Lisp have different examples of how to solve this). The ultimate remainder of problems are likely really obscure, and are probably indicative of code smells (e.g. VectorF<3>).