(no title)
fluffy87 | 5 years ago
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“.
yokaze|5 years ago
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.
lifthrasiir|5 years ago
It is beneficial to view C++ as a two-stage programming language, where the first stage runs templates and emits instances and the second stage runs them in the actual target. When C++ templates are said to be "untyped", that's really about the first stage [1]. You can't be very sure that templates act as intended for all valid inputs because it can't statically determine types before the first stage. Of course you can still write almost-working templates.
[1] Specifically the template invocation. C++ templates do have types for compile-time expressions and for that reason it was a wise move to move most of them into constexpr functions.
gpderetta|5 years ago
edit: the static/dynamic distinction pointed out elsethread is a much better description.
kupopuffs|5 years ago
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|5 years ago
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/21...