5 ms·
I agree. Many of us like it about C that we can build intrusive data structures easily enough. The price is more complex memory management and locking protoco
by cryptonector 8y ago
I agree. Many of us like it about C that we can build intrusive data structures easily enough. The price is more complex memory management and locking protocols, but in some cases the price is too steep in actual run-time cost. The apples to oranges comparison is not telling about whether Rust produces better code than C, but it shows how Rust's design choices force themselves on the coder and yield better results in the end. When you stay away from unsafe code, Rust makes one write code that is much easier to reason about, especially in a threaded environment. Performance is nice, but the nicer thing is correctness -- being able to get good performance along with correctness, now that is really nice.
- TheDong 8y agoI think this is more a result of rust having good generics. If c were built with good generics and memory management (not that garbage preprocessor stuff), I expect similarly expressive and good data-structures would be built. C++ is an affirmation of this because it happens to have good libraries of data-structures which are not really very different from rust's. I don't think this is as much "rust's design forces the coder to do this" and more "c makes it hard to do as nice of a design"
- vnorilo 8y agoRight. In C, correctness is by convention, not enforced. C++ allows "userland" enforcement via RAII. There are, however, pieces of compiler magic partially outside the type system (const, &, &&) - you can't specify such behavior within C++. Rust does more of this magic in ownership. If you just want a particular instruction soup, all of them will get you there. It's a question of ergonomics, convenience and the kinds of compiler guarantees that we want.
- cryptonector 8y agoC is also expensive in that it's practically impossible to get correctness in large codebases.
- zbobet2012 8y agoThe Linux Kernel would beg to differ. I love Rust, I love strong typing, but statements like this are what make people scoff at its evangelist. People can and do get C right, in safety critical systems, at larges scale, all over the world.
- bboreham 8y agoWhat definition of “correctness” are you using here? Bugs are found and fixed in Linux all the time.
- jacquesm 8y agoBugs would be found in a Rust codebase all the time as well. The difference is that a certain class of bugs is going to be absent from safe usage of Rust. (Unsafe Rust gives you just as much rope to hang yourself with as C).
- newacctjhro 8y agoUnsafe Rust has a little less rope than C because there are less cases that can lead to undefined behavior (see https://doc.rust-lang.org/nomicon/what-unsafe-does.html https://doc.rust-lang.org/nomicon/what-unsafe-does.html and https://doc.rust-lang.org/reference/behavior-considered-undefined.html https://doc.rust-lang.org/reference/behavior-considered-unde...). However, once you trigger UB, it's the same. By the way, Rust devs are working on a mathematical formalization of those rules. Here's a blog post about a part of this effort: https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html. (There are similar formalization efforts for subsets of C, that led to software like the CompCert verified compiler)
- coldtea 8y ago>The Linux Kernel would beg to differ And it would be wrong in differing. Memory and synchronization bugs the kind of Rust prevents are found in the kernel all the time.