← Back to context

Comment by ashton314

3 years ago

C is valuable because you shoot yourself in the foot over and over. Once you’ve dealt with use-after-frees, segfaults, memory corruption, then you will really appreciate what Rust does for you. Sure, you can learn Rust up front, but I on,y appreciated it after I had spent some time acquainting myself firsthand with the problems it’s trying to solve. Just my opinion though—Rust is a ton of fun.

C is valuable because it puts an emphasis on ABI. In that sense, it’s a gentle introduction to assembly - functions map 1-to-1 with generated subroutines (modulo inlining), and no monomorphization/templating encourages code reuse at the instruction level. Those philosophies are important stepping stones to understanding concepts like dynamic linking, calling conventions, how registers behave, etc.

Of course, you could emulate this behavior with Rust using extern and unsafe and whatnot, but the affordances of Rust steer you away from those details in favor of the higher level abstractions it offers. Which is what you want for 99% of software development, but when you’re writing platform specific code (e.g. OS startup, context switching, optimized SIMD) that a compiler can’t reliably generate, it helps to be able to quickly prototype something with C and then tweak certain instructions in the generated assembly subroutine until you get what you want.

  • You can write Rust in a C-like style, without generics and without traits. The output assembly will likely match the C output too.

My perspective was kinda the opposite: I'd already heard of use-after-frees, segfaults, memory corruption, etc. And I was very glad that I didn't have to deal with these as a programmer in high-level languages (JS, etc). As such, learning C was pretty daunting, knowing that even expert-level C programmers tended to hit into these issues, and there seeming to be 1001 rules that one has to learn to avoid them.

Rust provided a way into low-level programming without having to deal with any of these things at all. All I had to do was learn a few concepts like allocation and ownership. Easy-peasy compared to the above! This was especially true as when I learnt Rust I had need of it in production at work. I would not have had the confidence to put C code into production as a novice C programmer with no oversight, but with Rust this wasn't a problem at all.