Should I learn rust?
Should I learn rust?
Feel like everyone's been telling me it's the best thing since sliced bread. I'm just a hobbyist with like a single big project I'm maintaining but I'm starting to hate the code and idk maybe I should rewrite it in rust. Idk
Let me start by saying I love Rust and think it's great. I've been writing some personal stuff in Rust and it's all that I've been looking for.
However there is some stuff you said that makes me think Rust won't be something you would fully appreciate Rust. Firstly every project, regardless of language, when it becomes big it becomes a hassle to maintain, especially if you're not experienced enough to have set up a good architecture from the start.
But more importantly, a lot of Rust benefits are stuff you didn't mention, and some of the stuff you mentioned is not that important.
Finally I would like to finish up saying that Rust has the most excellent documentation: https://doc.rust-lang.org/book/ read that, then maybe do these https://github.com/rust-lang/rustlings if you get to the error types and are not drooling over the language, it might not be for you.
Thanks for the detailed write up.
One more reason I might not have mentioned is that Rust is low level and has a good developer experience. At least I heard. The whole compiler is your best friend thing.
Idk I guess I'm hoping it will teach me those concepts better without making me frustrated in the way C++ and C did. Those feel like they're excellent languages that were no doubt revolutionary in their time but are now lumbered with legacy and unintuitive things. Maybe it's false hope. Rust certainly looks intimidating but everyone says the tools and docs are amazing.
I've decided I'm gonna learn it for sure. Whether I rewrite the project or not I'll decide later.
Yeah, that's a good approach, learn it and it's one more tool under the belt.
That being said, I think you need to have some good level of proficient in C/C++ before lots of the Rust things make sense. I'm not sure what frustrated you about C/C++, and if you'd like to ask questions about that I'm happy to try to answer them. But a lot of concepts are the same just shown under a different light. For example, on C/C++ you chose to use stack or heap by declaring variables or allocating memory and storing it in pointers, in Rust you don't allocate memory directly, instead you use types that store information on Heap, e.g. Box. I think that's a lot less intuitive, and requires you to have a good grasp of heap/stack before it makes sense, but it prevents you from doing stupid stuff you might do accidentally on C/C++ like store a pointer to a stack object after it goes out of scope.
But I might be wrong, it might be that for me all of that made sense because I knew C/C++ but that to you it will make sense regardless, and might even teach you those concepts that are useful on C/C++ too.
well, you can, can't you? there are several different synchronization primitives in the standard library that lets you do that if you really want it
Yes, you can have a
OnceLock<RWLock<T>>
which is something that will get initialized at some point, and then you can acquire a lock on it for either read or write. To use it you need to check and handle both conditions, so it's really secure.However if you're writing a single threaded application a global
let mut
should also be safe, but Rust doesn't know if your application is single-threaded, or even if it is, it might get imported by others that isn't. So you're forced to consider the safety of things that might not even be related to what you're doing. Which was my point, if you're writing a simple CLI single threaded app, the compiler blocking you from having a global variable seems pedantic and unnecessary, because it's forcing you to deal with the edge case of your app becoming multi-threaded in the future.Don't get me wrong, this is part of what makes Rust great, but it can be EXTREMELY pedantic.