3 ms·
> I found rust significantly harder to learn than C language itself maybe, but you also need to learn ecosystem, libs, build systems, testing. Benchmark coul
by riku_iki 3y ago
> I found rust significantly harder to learn than C
language itself maybe, but you also need to learn ecosystem, libs, build systems, testing.
Benchmark could be: how fast you can learn and bootstrap some type of app of your choice: high performance DB or torrent server, etc.
> You essentially can’t write rust at all until you understand rust references, lifetimes (implicit and explicit) and the borrowchecker
why is that? You can write rust the same way you write C but with nicer syntax, standard lib and build system and more potential to future expansion.
- josephg 3y ago> but you also need to learn ecosystem, libs, build systems, testing. That’s a really good point that I hadn’t thought of. If we include header files, compiling and linking, makefiles and CMake and the mess of dealing with 3rd party libraries in C - well, yeah. All that stuff is probably worse than learning the rust borrow checker. I think I’ve forgotten how horrific that mountain is for beginners because I learned most of it decades ago, while the pain of learning rust is still fresh. > why is that? You can write rust the same way you write C Because I use pointers everywhere in my C code. Rust’s borrow checker simply won’t compile my code if I transliterate it directly from C. There are software patterns which work well in rust with the borrow checker in mind - but they take time to learn and get used to. Until you do, you simply aren’t productive.
- riku_iki 3y ago> Because I use pointers everywhere in my C code. Rust’s borrow checker simply won’t compile my code if I transliterate it directly from C. borrow checker is more relevant to C references I think. For pointers you can use Arc or Rc and don't worry about borrow checker. Disclaimer, I am not a rust or c coder, so my opinion has a high chance to be wrong..
- josephg 3y agoIf you want to learn rust, there really isn’t a way to avoid learning lifetimes and the borrow checker. It’s a core part of how the language works. You can probably get partway there with Rc and by cloning stuff everywhere but you’ll still run into borrowck problems. Rc doesn’t turn off the borrow checker. (Nor does unsafe). But then you won’t have the tools to solve your problems. And you also won’t know how to use most of the standard library or any crates. That’s no way to write rust. > Disclaimer, I am not a rust or c coder, so my opinion has a high chance to be wrong.. I’ll take a step back. I hope this is helpful to someone and not patronising. Go and similar languages are memory safe because no matter what go code you write, go runs your program with a GC that makes sure your variables are freed correctly only when it’s safe to do so. Rust’s safety is very different. It comes from checking at compile time that your program is written in a way that obeys a bunch of complex rules. For that to work, you have to write your code very carefully. If you mess up, the compiler doesn’t fix it for you. It just refuses to compile. So you have to write your code with those invariants in mind, or your program won’t build at all. C code generally doesn’t obey any of rust’s rules - for obvious reasons. If you were to just blithely translate C to rust code, the rust compiler will refuse to compile your program because the rules aren’t being followed. To write rust code that the compiler accepts, you need to first learn the borrow checker’s way of seeing the world. Then you need to restructure your code to work in accordance to rust’s rules. And sometimes that’s a super obscure and tricky problem. Weirdly, I think it’d be much easier to go the other way. Any compiling rust program could be translated into a memory safe C program if we had a compiler that did that. (I think). And lots of C programmers say learning rust made them better at C - because rust’s rules genuinely teach you to be more disciplined with memory and show you some clear rules for making C code that’s much less error prone. Not learning the borrow checker is like not learning how objects work in Python. You could write some simple programs. But you’re going to have a bad time, especially if you try to do anything nontrivial, use library code or read anyone else’s programs.
- adamnemecek 3y agoYeah, that's what I meant by productive. Not like learn the language but like build stuff.