4 ms·
> Now this whole section feels a lot like "I'm trying to code in Rust like in C and it doesn't work and it frustrates me". A media codec is a very well underst
by ajross 9y ago
> Now this whole section feels a lot like "I'm trying to code in Rust like in C and it doesn't work and it frustrates me".
A media codec is a very well understood, highly optimized thing with established idioms that are already well-matched to the capabilities of the hardware (and in many cases are taking advantage of hardware features explicitly designed for the codec being implemented!). Demanding that we start writing codecs differently isn't the same thing as telling a app UI developer they need to get used to traits instead of inheritance.
If rust can't handle the existing idioms for this problem area, that may need to be seen as a problem with rust, not the programmer.
- simias 9y agoThat's not really the point. I'm sure whatever the original code is doing could be copied directly, including calling raw assembly code (which optimized codecs often end up doing to micro-optimize as much as possible). You'll just need copious amounts of unsafe code. But then what's the point? You might as well keep your existing code. I guess it would make sense if you wanted to standardize your cobebase and move everything to Rust, but I doubt that's much of a use case nowadays. Now if you write a brand new codec it might be interesting to start in safe Rust and once you're ready incrementally add unsafe code where it matters to improve performance while limiting the unsafe code as much as possible. Rust gives you the choice, C is just unsafe by default. Coders have to write things differently if they want a different result, as should be expected. If the only metric is performance at all costs then assembly beats everything else.
- pcwalton 9y ago> A media codec is a very well understood, highly optimized thing with established idioms that are already well-matched to the capabilities of the hardware (and in many cases are taking advantage of hardware features explicitly designed for the codec being implemented!). Hold on. We aren't talking about modifying the codec itself, or how it's implemented at the machine level. If it weren't straightforward to generate machine code that matches how the codec is designed to be implemented, that would be an issue with Rust—but that isn't what this thread is about. We're only talking about the particular language idioms used to create that implementation.