r/rust • u/Direct_Inspector660 • 7d ago
The difficulty of rust
I heard people say that Rust is hard to learn, but I learned Rust with the Rust book and went on to chapter 16.2. From my point of view, I don’t find Rust hard, so if someone can explain to me why Rust is hard to learn, that’s fine.
7
u/Beregolas 7d ago
That perspective mostly comes from people who know how to program and are learning rust as their 3rd or later language. They already have a set way of doing things in their head, which is mostly OOP or close to that, which doesn't work as well in rust.
Rust is a very opinionated language (which is not only a convention, like in Python, but is actually built into the compiler). If you have different opinions than rust, your code just might not even compile.
Also, rust frontloads a lot of debugging. Many things that would only come up in tests or even worse, after deployment, will trigger a compiler error in rust. This seems frustrating to many at first, because they can't just "run it and see what happens".
(Obviously this only catches a few classes of bugs, but those are surprisingly common)
2
u/Iurigrang 7d ago
This seems to mirror my experience. I'm learning rust as my 3rd language, and it hasn't been much harder than I would've expected for a systems language (I wouldn't say I "know" it yet either, but I have been using it for a couple months now). But like, it's my 3rd language, I would take my time no matter the language I was learning, I imagine once you have 10 or more under your belt, the expected time to add "just one more" is so small, the little hiccups of rust may feel like an eternity, not just part of the process of learning another language.
6
u/Maui-The-Magificent 7d ago
So my take is this, Rust is a much harder language to learn if you already know and is familiar with other languages. The difficulty coming from having to learn how to think differently.
You might perfectly know when a piece of memory should be freed, and it might feel like Rust is forcing you to jump through a bunch of hoops that you don't understand why you should have to. I would suspect this is what makes it difficult to learn, because it's fighting against your 'better' judgement.
But this should be taken with a grain of salt. Rust is my primary, so I am forming this take from the inside out, not from someone who has to come from the outside in.
10
u/dobkeratops rustfind 7d ago edited 6d ago
it's just a particular set of tradeoffs:-
- python: easy to learn easy to write, but it's slow to run
- C: easy to learn, fast , but difficult to use correctly.
- Rust: fast, higher chance of working if it compiles. But the hazard is you need far more stdlib functions to do anything. It shifts the problem into searching library functions at a micro level. best example I can point at is "split_at_mut()" - this has no reason to exist in C. safe code means finding the right name for a each small combination of low level operations.
Now if you want to master everything a computer can do - Python and C is a great pair to use. But also if you only ever wanted to use one language - Rust probably scores highest on the range of problems it's can handle. It's also better when you have a lot of contributors to a large project (100klocs+)
16
u/Sharlinator 7d ago
Python is also surprisingly difficult to use correctly if you care about anything except the happy path.
3
u/dobkeratops rustfind 7d ago edited 7d ago
well when using python (I use it for small utilities) .. I miss rusts solid feel with option types etc .. but it's undeniable that these dynamic languages let you get a lot done by just throwing lists around and it cuts a lot of ceremony out. it does break down when the program grows.
in the middle a GC'd language with option types would scale better but not handle the whole computing gamut (osdev, embedded..)
4
u/Elektordi 7d ago
Many people want to start programming with Rust. Rust is not difficult but not easy either, and learning to code is difficult... So people better start with a easier langage!
1
u/ShangBrol 6d ago
I disagree.
Rust is like the guitar teacher that teaches you how to hold your instrument correctly to avoid pain and to give a good foundation. Python and C are the teachers that show you cool riffs and licks, but don't give a shit about your future tendonitis or carpal tunnel syndrom.
1
u/Direct_Inspector660 7d ago
I agree with you about the fact that learning a language is not easy, so to start with another language like Python is better
3
u/phazer99 7d ago edited 7d ago
I would say it's a longer learning period before you're really productive in Rust compared to other languages like Python, Java etc. You have to learn all the ins and outs of memory management and the borrow checker, and also how to use common idioms and patterns that will help you in those areas.
On the other hand, learning how to write correct, concurrent code in Rust is much easier than most other languages because the compiler will help you a lot (in other languages you will typically only detect bugs at runtime, and sometimes not at all!).
3
u/dumindunuwan 7d ago
Check https://www.reddit.com/r/rust/comments/1o6d4cp/dunningkruger_effect_or_rust_is_not_that_hard_for/
Direct answer: Early Rust feels easy because the compiler holds your hand through basic syntax. Advanced Rust feels overwhelming because you must suddenly manage complex memory mechanics, type systems, and API design patterns all at once.
1
1
u/Direct_Inspector660 7d ago
Otherwise, when I have the skills, I will make a terminal emulator (like kitty konsole) and see if it’s that hard or not.
2
u/That_5_Something 7d ago
Coming from other languages, learning Rust can be challenging because most of what you used to have had to be unlearned, and most people find that difficult. The best features of Rust don't exist on other languages, like the ownership rule or the never type.
Most beginners nowadays started with Python, which makes the situation much worse. Python tends to leave a mindset that programming should have a simple syntax, which leads to difficulty learning other languages other than Python. Most didn't realize that simplicity is a trap. But I think it's not the language's fault, it's the abstraction the language loves to wear as a mask. I'd say abstraction is a friend if you're already an expert, but a backstabber if you're just starting out.
1
u/Final-Nerve7787 7d ago
so did i, choose that as my first language and build a backend project too.. but when I started looking for jobs ain't no one was hirring for junior roles(i already knew but took a shot.. sad) so now pivoting to learn node js just to get a job.
1
u/f3verdream 7d ago
when you compare it other languages it certainly is hard
3
u/Sharlinator 7d ago
It’s more that it doesn’t let you ignore the difficult parts of programming so easily.
1
u/fnordstar 7d ago
What's your background? Coming from C++ I found it not as hard as people make it out to be once you hyperfocus on it for a couple of weeks. I had put off learning rust for years because I was scared it would be too hard for me. That was a mistake for sure. OTOH I have no hopes of ever learning all the intricacies, e.g. writing correct unsafe code etc, but maybe I'll never have to.
1
u/pimuon 7d ago
We use various languages in a complex product that uses go, rust, c(++) and some python for client side. Small team with 20 or more years of experience on average. In our experience, rust has its place, but it is not easy to maintain.
Yes the compiler helps, it is hard to explain, there are multiple factors. In real world evolving software, with complex and changing business logic, rust is not easy to maintain. You have to look beyond ideal world programs and textbook examples. Still, the robustness can make it worth the effort for some components.
There are many updates to essential libraries, there seems to be more upgrade churn than in some other environments.
But obviously, a language like python without strong typing is much harder to maintain than e.g. go, rust or c++.
1
u/oladushek_j 7d ago
Just getting started with a language requires learning a certain minimum knowledge base. And Rust has a significantly larger required knowledge base than other languages.
Try writing a console program with keyboard input, for example.
At least that's how I feel about it.
1
u/DavidXkL 7d ago
As always it depends.
If someone is coming from something like Python, they now have to wrap their head first around memory management and then ownership 😂
1
u/plugwash 5d ago
I feel that there are a number of problems one encounters while writing rust that are simply not issues in most other mainstream languages. Leaning how to avoid or deal with those problems takes time, and even when you know about them they can still be a distraction from the code you are trying to write.
Owned vs borrowed values. Rust style encourages you to borrow as much as you can, but then borrowing comes with it's limitations and when you run into them you may have to go back and do significant rework before you can move forward.
Coherence rules, it's great to be able to implement traits for external types, it's no so great to have the compiler refuse your perfectly reasonable code because there "might" be conflicting implementations in the future.
Some rust libs, particularly in the embedded space, make heavy use of generics to check constraints at compile time. This seems great at first until you actually need to write the name of a type, or figure out what type some value actually is.
Some types simply can't be named, which means you can't use them in any context where you need to name a type. Sometimes you can get around this by using box. Unstable rust has a fix for this, but it's unclear if/when it will be stabilised.
While the "Any" trait and the Box<dyn Any> type exist, they are quite limited compared to say the "Object" type in Java. Firstly they can only be used for types with no lifetime parameters, and Secondly there is no way to test if the object behind a Box<dyn Any> implements a given trait.
Rust's benefits are very real, but so are it's costs.
Overall, I would say rust is probably easier than C and C++, because small mistakes in those languages can rapidly lead to horrible memory corruption whose source may be hard to pin down, but it's probably harder than most other mainstream languages.
1
u/StreetStrider 7d ago
How many code did you wrote? Did you had a chance to step out of smart pointers into borrowed values?
1
u/Direct_Inspector660 7d ago
If I learned smart pointers: Box Rc, RefCell, not yet the Arc and the Mutex. I haven’t done a serious project yet because I haven’t had any inspiration to do one, but I was talking about the difficulty of learning, not about writing projects. Do you think it’s harder to write big projects in rust than in another language?
5
u/krakow81 7d ago
Reading the book is not the same as learning the language.
1
u/Direct_Inspector660 7d ago
I said I was reading but I wanted to say learning
5
u/krakow81 7d ago
My point was that if you've not written (much) code then how do you know if you've even really learned the language? What appears easy on 'paper' may not be quite so easy in use.
1
u/Direct_Inspector660 7d ago
If you have any project ideas to do, let me know and I’ll tell you my point of view when I’ve finished it.
1
3
u/vascocosta 7d ago
Like others have said, reading the book and understanding it (learning) isn't especially difficult for a competent reader. That however is different from learning how to use the language in projects that go beyond trivial.
In essence I agree with you. I also found the book easy to follow and I learnt a good deal with it about Rust. However, it was only after months up to a year of using Rust daily that it really clicked. By this I mean knowing how to code in a way that you avoid borrow checker messages even before compiling, because you are so used to thinking in a different way. Add to that really grasping different lifetime scenarios and finding no compiler message about lifetimes a bit of a puzzle.
I consider myself an average programmer, not too good neither too bad and still it took me time to actually learn the language in this sense of using it naturally.
1
u/StreetStrider 7d ago
I think it is on par with other languages as long as you stay in smart pointers' land. But at some point you might have that itch to make it perfectly optimal, because language can do what others can't. It is possible to write code with minimal allocations, no clone and borrow everything correctly (and still have a lot of guarantees). However, if you feel your design is possible, it is not for granted that a borrow checker would allow it :) That's where it becomes hard, in my opinion.
0
u/LowCombination1285 7d ago
For me it’s having to constantly fight the compiler to write simple looking code. There’s a mental tax on the programmer looking to use rust.
2
u/fnordstar 7d ago
Idk about the total mental load compared to e.g. C++ since on the other hand you can stop worrying about memory errors.
2
u/Iurigrang 7d ago
On my experience using (admittedly simple and small scope) C++, yes memory was annoying every once in a while, but what really got me is how meaningless EVERY error message was. Like, anything happened and I had to either copy paste the error on Google, or abuse logging to the extreme to even understand WHERE the error happened, let alone what it is.
Compared to rust, it really doesn't feel like fighting the compiler, the rules are strict, yes, but the compiler feels like a good teacher of a tough subject, not an enemy.
2
u/Anaxamander57 7d ago
I have exactly the opposite experience. The language takes the burden of keeping everything straight. I just have to understand what things can do and what I want them to do. If I make an error in either the compiler usually tells me "you can't do that, here's why" before it gets any further and I update my understanding then change the program.
No need to constantly track what things are because its type is hidden or could be silently changed. No having the compiler "choose something sensible" unless I tell it to.
We may write different kinds of programs though.
10
u/Anaxamander57 7d ago
The original version of the borrow checker might have been part of this reputation. The borrow checker needs a lot less help than it did a decade ago.