Rust is considered difficult to learn by many people. Indeed, when I learned it,I considered it to be the hardest programming language up to that time I’ve met.And that says something, since I have a habit of learning whatever language Ifind interesting. Looking back, I’m not sure I was correct, C++ is probablyharder ‒ but it was distributed into much longer time than learning Rust.
So, this is my point of view what I believe are the reasons. Also, I’ll claimthis upfront ‒ I don’t consider it necessarily a bad thing for a language to behard to learn, not when I get something in return for the investment.
Rust attacks hard problems
There are languages that are simple. To point one of them, look atlua. The complete language manual is shorter thanintroductory book to most other languages. It has something like 4 or 5 datatypes and you can’t add your own. Why is it so?
Because lua, and other languages, made different choices about what their goalsare. If you start designing a language with the intention of creating a verysimple and minimal language, you will end up with a very simple and minimallanguage (if you’re any good at designing languages). The language may not besuitable in some situations, but that wasn’t the goal.
On the other hand, if you declare upfront that your language needs to be able tosolve any hard problem anyone thinks of, run fast and be safe to use then you’llprobably get your wish, but it’ll hardly be simple.
And that’s what the authors of Rust decided. To be able to do whatever is neededdone. But Rust is not the only complex language because of that. Look at C++ ‒Rust at least keeps the complexity somewhat sane.
However, this is difficulty that anyone trying to enter the low-level world ofsystem programming should expect. All these details about where a memory isallocated, how much memory it takes, that were not important in other languagessuddenly surface. But that’s because you need the control, isn’t it? Otherwise,you would use the simple language, as it would be sufficient.
The language is honest
This is similar to the above, but not completely.
When the language designers want to solve a problem, there are two generalapproaches.
First one is to hide the problem from sight and let the language handle itsomehow. The fact it isn’t always the best way doesn’t matter.
The other approach is being honest about the complexity of the problem, admitit, but arm the programmer with tools to handle it.
This means the beginner must grasp the complete complexity of the problem, butmakes it easier in the long term ‒ simply because after solving the problems,there’s no beginner any more and because sometimes having the needed tools andnot fighting the language to get to the problem is just easier.
Rust is different
One of the problems why I found Rust hard to learn was that it looked similar toother imperative languages on one side, but introduced a lot of novel concepts.It has all these cycles, conditions, functions, like everyone else. But it alsohas the ownerships and traits and lifetimes. These do have its reasons, but theyfeel alien at first ‒ but not alien enough to completely switch mental models.But that also make the language interesting.
What I mean about switching mental models. If you coded in Python and then triedHaskell, you’d see at the first glance than nothing is the same. But withRust, I started to code like I did in C++, because it looked a bit like C++. Putsome callbacks here and there… and then the compiler complained, because suchmodel doesn’t fit. I tried to force it and after a time I got a really hairyAPI I didn’t like a bit.
The problem here is two-fold:
- It is not clear upfront the language is different than whatever else one mightalready know and that the other knowledge needs to be put on a shelf for awhile.
- There are many books about good design in the OOP world, many books andclasses how to structure a program in pure functional world. But not many(none?) books about best practices for a world based on ownership andcomposition.
The compiler is a very strict teacher
All things together, Rust insists that your program will be correct or it won’tcompile. Strict typing makes you think about the relations in your program. Itchecks that you don’t get data races. It will tell you if you try to free somememory too soon.
This is a good thing. It makes sure your programs are better than of thecompetition (if you manage to compile them, of course), that they are lesslikely to crash and burn or something even worse. It makes the language easierto use (imagine if you had to actively think about all these things insteadof relying on the compiler to check it for you ‒ welcome to C).
But at the same time, it makes learning it a bit harder, because it insists onyou learning everything needed to write a good program. An average is notacceptable.
If you just learned about how to write a function, it doesn’t feel veryencouraging when the compiler starts to talk about data races (what are these,anyway, you ask at the time). A program that is subtly wrong would be fine atthat time ‒ at least it would run.
But in the long run this makes you a much better programmer. Even in otherlanguages.
Today, there’s a lot of very good documentation about this ‒ it at leastexplains why such things are incorrect and how to fix them.
People say it’s hard
This one comes down to perception. If so many people say Rust is hard to learn,then it must be true. The fact they learned in times when there was no or littledocumentation doesn’t change a thing here.
What to do about it
Documentation and resources help a long way. However, I believe the biggestissue is perception and expectations.
So, if someone asks (or if you’re considering learning Rust and ask yourself):yes, Rust is hard to learn. But not necessarily slow to learn. A month or soof experimenting in the evenings after work goes a long way. By that time, youprobably could start contributing to the Rust compiler itself, with some littlehelp ‒ and compilers are one of the most complex pieces of software that exist.
What should a beginner in Rust expect:
- Some frustration that his or her programs don’t compile on the first (ortenth) attempt.
- Having to understand a lot of problems not known to exist before.
- Satisfaction after discovering how much can be learned with a very strictteacher and probably enjoyment from the learning itself.
- Find the language different and interesting.
- Becoming a better programmer, even in other languages (for example, ownershipis just formalisation what most people do in languages with manual memorymanagement anyway, but Rust makes sure it becomes second nature).
- Meeting some very nice people in the community.
- Discovering that it’s possible to both write and run programs fast at the sametime instead of having to choose.