3 ms·
> Wrong. Indeed, thanks for the correction! > it seems to me that they are more similar than different. I think the Haskell vs Python comparison is accurate.
by fluffything 6y ago
> Wrong.
Indeed, thanks for the correction!
> it seems to me that they are more similar than different.
I think the Haskell vs Python comparison is accurate. Rust generics are strongly typed (definitions are checked), while C++ templates are "weakly" typed (type checked when they are instantiated). In C++ it is trivial to write templates that will never type check when instantiated, while in Rust this is impossible.
- gpderetta 6y ago>> Wrong. >Indeed, thanks for the correction! Sorry for the brusque response, I had a "someone is wrong on the internet moment". >Rust generics are strongly typed (definitions are checked), while C++ templates are "weakly" typed (type checked when they are instantiated). True. The usual solution is to force-instantiate them against archetype classes. While it is not perfect it is a good approximation.
- fluffything 6y ago> True. The usual solution is to force-instantiate them against archetype classes. This is correct, but you not only need to make sure that they accept an archetype class, you also need to make sure that they reject all others. This often requires writing and instantiating a substantial amount of code for testing purposes, which often ends up as large or larger than the actual logic itself. I suppose you already know the pain of doing this, but for those who do not, it is like testing a function in python for all possible inputs. Can be done, but is a lot of work. In practice, most generic C++ code is not tested in this way due to how painful it is to do so. So what in Rust takes no work, takes a huge amount of effort in C++.