4 ms·
Dynamic languages for sure - you just dynamically dispatch your method call based on the type of the object in the container. But what C++ is doing (and static
by xiii1408 8y ago
Dynamic languages for sure - you just dynamically dispatch your method call based on the type of the object in the container.
But what C++ is doing (and static languages with metaprogramming in general) is specializing and statically inlining everything at compile time so the assembly just takes the fastest path every time; no runtime cost.
I'm unsure which static languages do and do not support partial specialization. My understanding is that the current iteration of Rust doesn't have partial specialization, but maybe it has other features that could do what this post is doing?
I'd be interested in hearing people's perspectives on the metaprogramming power of different statically typed languages - people have expressed interest in me building libraries like this in Rust and a few other languages.
- steveklabnik 8y agoI don't fully grok all of the details in the post, but yes, Rust does not have specialization. However, given the way traits work, I don't think it would be needed in Rust. Serde is the most popular serialization/deserialization framework. You get a Serialize trait, that you implement for a given type. It already calls that specific implementation for that type. Buuuut I'm probably missing something.
- stochastic_monk 8y agoHe specifically asked about partial specialization, which is akin to currying for templates.
- steveklabnik 8y agoYeah, this is what I mean by that I don't 100% understand all the nuances. I mean, I understand what that feature does, but given that Rust's system works quite differently, I'm not 100% sure what an exact translation would be.
- deleted 8y ago[deleted]
- lostmsu 8y agoJust have a generic abstract class with the required public interface, then have two implementations of it, generic one, and a special one for trivially copyable types. Then you can have a factory, that creates an instance based on the element type. Can be done in Java and C# alike.
- Koshkin 8y agoThe post gives an example of using an interface with static dispatch. This is in contrast with a regular interface (an abstract class) which implies the use of dynamic dispatch.
- lostmsu 8y agoI don't think it matters in the scenario though. The cost of dynamic dispatch will be negligible in comparison to remote call costs, even into a different process on the same machine. Besides, there are techniques to avoid dynamic dispatch for generic specializations, at least in C#.
- smoothdeveloper 8y agoAnd even more techniques in F# in it's type system and inlining