3 ms·
C++'s templates are more expressive than Rust's generics. Rust is adding stuff to try to catch up (specialization, const generics). You might see the extra powe
by burntsushi 8y ago
C++'s templates are more expressive than Rust's generics. Rust is adding stuff to try to catch up (specialization, const generics). You might see the extra power as an anti-feature, and that's fine, but it's undeniably useful to lots of folks and is undeniably a trade off.
- masklinn 8y agoBut doesn't the fact that Rust is managing to add these features mean the lack thereof is not a limitation of classical parametric polymorphism? Not that they're necessarily trivial to integrate, especially when the people working on it would rather try for the stars of genericity (e.g. dependent types versus const generics).
- burntsushi 8y agoI would be surprised if Rust's type system winds up supporting everything C++ templates do. But maybe I'll be wrong, or the only things not covered will be niche and easily worked around. I don't know.
- saghm 8y agoI feel like part of the reason that I don't run into issues with Rust having less expressive generics than C++ is that Rust has a ton of other useful meta-programming features; a lot of the crazy things I've seen solved by C++ templates can be solved in Rust via things like proc macros.
- htfy96 8y agoJust wondering if it's possible to implement something like expression template used in Eigen3 in Rust. C++'s template can be used in more than generics.
- weberc2 8y agoSure, but those are different tradeoffs than those listed above. And some of the warts with C++ templates might not be inherent to supporting the features that C++ templates offer over Rust generics--for example, what features are enabled by error messages that point into the expansion of a template rather than a type error at the template itself?
- burntsushi 8y agoThey aren't different. The last bullet point in munificient's comment is a point about expressiveness. I honestly don't know what point you're trying to make here. This really shouldn't be controversial.
- weberc2 8y agoFair point, I missed the last bullet. To me, munificent's comment reads like a false dichotomy--you either have the Java's problems or C++'s problems. I was pointing out that there are other systems that largely have neither--namely that you can have template-based generics that perform better than Java and are friendlier than C++. He may well not have meant it that way, but that's the context for understanding my posts.
- stcredzero 8y agoC++'s templates are more expressive than Rust's generics 80/20 rule applies here. 80% of the boilerplate can be eliminated with 20% of the expressiveness.
- burntsushi 8y agoYes. I agree. Some might even argue that this applies to Go itself: its builtin generics get you a lot without bringing in the full baggage of user-defined generics. There's really nothing in my comment that suggests I think otherwise, so I'm a bit confused by your comment.
- stcredzero 8y agoI'm expanding on your comment about trade-offs. I tend to like nuanced views of cost-benefit trade-offs in language design. It is a complicated subject, after all.