4 ms·
> Both are "portable assemblers" I don't tend to think of Rust as "portable assembly", and this is indeed one of the points where I think it differs the most f
by skohan 6y ago
> Both are "portable assemblers"
I don't tend to think of Rust as "portable assembly", and this is indeed one of the points where I think it differs the most from C. I think of "portable assembly" as being applicable to C, because it is some version of a "minimal" level of abstraction for a high-level language. Rust is very much a tool for abstraction, and one of the USPs of rust is that the compiler abstracts away the low-level details of memory management in a way which is not as costly as other automatic memory management strategies.
Maybe it's due to lack of experience, but with C code it's fairly easy to look at a block of code and imagine approximately which assembly would be generated. With highly abstract Rust code, like with template-heavy C++ code, I don't feel like that at all.
- pornel 6y agoWith a bit of experience you get the same in Rust. Rust does not abstract away memory management. For example, it never heap allocates anything implicitly. It inserts destructors, but does so predictably at end of scopes, in a specified order. Rust heavily uses iterators with closures, but these get aggressively inlined, and you can rely on them optimizing down to a basic loop. For code generation they're not too different from a fancy C macro. And if in doubt, there's https://rust.godbolt.org/ https://rust.godbolt.org/ (don't forget to add -O to flags)