5 ms·
>The Rust's generics and macros are much weaker than provided by C++ templates coupled with C macros. Although, this is also not so crucial. That's a very stra
by simias 6y ago
>The Rust's generics and macros are much weaker than provided by C++ templates coupled with C macros. Although, this is also not so crucial.
That's a very strange way to put it IMO, I'm not sure what is meant by "weaker" here. They are stricter and as such can require more work to use effectively, but weaker is a weird way to put it.
- wtetzner 6y agoI would say Rust macros are considerably stronger, given it supports procedural macros.
- steveklabnik 6y agoI think that the way they mean is that there are less restrictions, which means you can do more with them, which makes them more powerful, in a sense. Words are hard.
- Karliss 6y agoC++ template provides features that rust generics don't. I am not a Rust developer so correct me of some of these have been recently added. Rust generics being stricter would be something like them allowing to use only methods provided by trait, but I would call all of following design limitations making rust generics weaker. * passing integer as template argument - from what I understand some of rust standard library functions can't handle arrays with more than 64 or 32 elements due to this or something similar. And there is active work for adding const generics to rust. * variadic templates - there is a RFC for this * passing template as template argument * template specialization - C++ is somewhat moving away from this
- steveklabnik 6y agoThe first point has had its restriction lifted as of the current version of Rust, 1.47.0. Or rather, the standard library and arrays bit is fixed; the underlying feature is not in stable Rust, and so other libraries still can't make this work properly yet. Variadrics are desired by some folks, but aren't a particularly high priority. Template template parameters are unlikely to land directly in Rust; GATs will be roughly equivalent. And specialization has a nightly implementation, and is highly desired, but isn't done yet.
- fluffy87 6y agoC++ templates are „untyped“ or very „weakly“ typed at the kindest, while Rust generics are „strongly“ typed. That’s the main difference in these languages features. Saying that Rust generics are „weaker“ than C++ templates is technically incorrect, since they are actuall „stronger“. Using these terms to mean something else is definitely „weird“.
- kupopuffs 6y agoIn terms of ease of expression and using mental power, C++ templates may be a more powerful tool for some. Like you're describing the type system, they may be talking about actual effectiveness. Like productivity diff between python and others Basically, I'm not smart enuf to use rust
- TheDong 6y agoIf they meant "A more powerful tool", the right way to express that is "more powerful", not "weaker/stronger". However, if you look at that part of the article, they justify that statement by linking to this post [0] which is explicitly about how rust actually type-checks generics more strongly. The linked post has the opposite implication of what the author took it to mean, and that link makes it clear that they were referring explicitly to how they're typed, not to "actual effectiveness". [0]: https://users.rust-lang.org/t/generic-functions-c-vs-rust/21965/3 https://users.rust-lang.org/t/generic-functions-c-vs-rust/21...
- yokaze 6y ago> C++ templates are „untyped“ or very „weakly“ typed at the kindest, while Rust generics are „strongly“ typed. Can you provide your definition of strongly typed? According to my understanding, C++ templates are evaluated at compile time, and the resulting instance has to qualify all the static type checks of standard C++. The deduced types is always checked, and if there is no substitution fullfill the type check is found, it raises a compile error. The errors are super ugly, as there are no type constraints for template parameters, but funnily enough the template errors in C++ reminded me of playing around with Haskell without using function declarations. I would find it odd to call Haskell though untyped or weakly typed because of that.
- klyrs 6y ago> template specialization - C++ is somewhat moving away from this Uh oh... I love template specialization... what replaces this?
- Karliss 6y agoSome of the cases can now more easily be handled using costexpr if.
- ashtonkem 6y agoThis is part of why I think we should begin to move away from “weaker” and “stronger” as adjectives for programming; these terms add a value judgement that is not properly reflective of the more nuanced trade offs involved.