Reading the posts in forums makes me wonder if Rust is very hard

Hi Everyone, I just started to learn rust. When I am reading the book and writing few simple programs it feels like I understand Rust but when I try to read different posts and things people write , I never understand, it feels hard. Am I only one feeling this way or did others also feel this way in the beginning

2 Likes

There's definitely a way to go with this language, and you can program most things at any of the steps. Just because you're not yet at the next step, you can generally still write code that does what you want. What is important though, is being able to identify and parse out what you don't know, so that you can't get confused by syntax.

In my opinion, the order you should learn things is as follows:

  • Hello world
  • Number Guessing Game or other small toy example
  • Syntax and names of most things in the language
  • Generics
  • Lifetimes
  • HRTB
  • FFI
  • Unsafe code and UB (Interchangeable with FFI)

And up the steps you go.

I felt like this at the start too, especially with the alien feeling syntax of lifetimes or "adding" traits together. I came from C# where the type system was worded differently.

The posts in this forum can be broadly filtered into newer user questions, and experienced user questions. In experienced user question, you'll cover the more difficult to understand topics, while in newer user questions you'll cover stuff where people are just trying to understand syntax, modules, or borrowing and ownership.

My personal advice is that you just plunge yourself into a post, and see what it's about. If it's waaaay too high level, then start to look at the stuff before it. Soon enough all the pieces will fall into place, just maybe not all at once.

3 Likes

This question reminds me of something I read a few years back. I don't remember all of the details but it goes something like this: there is a popular journal in Mathematics that communicates recent discoveries that are worthy of sharing with the rest of the Mathematical community. A newly graduated PhD sent a question to an editor mentioning that they never really understood what was being talked about in most articles and figured they would when they earned their PhD. Turns out that they still didn't understand most articles even after earning a PhD. The editor mentioned that this is normal and admitted that they didn't either.

Anyway, I'm not saying that learning rust is like getting a PhD in mathematics, but your question reminded me of this story.

As for me, when I was learning this language I also had a difficult time following others discussions. And I still do. And I don't think that's uncommon and not entirely rust specific.

7 Likes

It's definitely true that rust has a learning curve. Depending on your current knowledge that curve can be steep.
From my own experience, after about a day I could code rudimentary apps, but I was already a polyglot so I already knew most of the concepts in some form or other.
After about a month I began to feel more intuitively comfortable with the borrow checker (one of the main sources of that high learning curve for most people), with a sharp reduction in compile errors on the first try as a result.
And somewhere in between I started producing worthwhile code (in that it went into production) that I spent the next year or so refactoring.
That last statement should be nuanced, because I learned Rust all the way back when it went 1.0, and idiomatic rust style has evolved somewhat since then, which can also cause the same kind of refactorings.

2 Likes

No you are not. I have been studying Rust and writing programs in Rust for a year now. Even if I have some Rust programs in production since nine months ago I find a lot of discussion here totally impossible to understand.

I'm sure there are many others feeling the same way.

I think the analogy to maths is quite apt. Rust is a huge language, I would not expect most people to absorb it all so quickly, if ever. In maths, when you are starting out in school with geometry and algebra you would not be expected to follow a discussion of calculus. That does not mean you don't learn a lot, you can do a lot of useful things with what you have learned. You will get to more complex things later. Or perhaps maybe never.

In my case it's amazing what one can get done in Rust without ever writing lifetime tick marks or macros or anything with generics or even traits. I write Rust as if I were writing C, until I learn something better along the way.

So stick at, read everything, let it float over your head if it is too much. Little things will stick here and there. In the mean time, if you can follow the Rust book you can already use Rust in interesting ways.

6 Likes

I'd say Rust isn't more difficult to learn, it just forces you to understand the difficult concepts up front. Your code won't compile if you don't understand enough of the details. While other languages will allow you to shoot yourself in the foot with incomplete knowledge, making you feel like you understand the language much sooner, but taking more time in the long run to learn because you have to learn about the footguns and unexpected features by being bitten by using the language wrong over time while implementing systems in it.

2 Likes

I think @OptimisticPeach's response really hits the nail on the head... When you are learning any language, there is always a large range of concepts to learn, and the deeper you look the more complex things are.

You'll find a lot of beginner questions as people are starting to learn the language and the fundamentals, but once people have an understanding of the language's underlying concepts and conventions they've developed a lot of the tools needed to solve intermediate problems themselves.

Later on as people are trying to push their knowledge they'll come across more advanced concepts (e.g. unsafe and lifetime variance) which aren't really present in other languages, or if they are they're implemented differently so the knowledge isn't directly transferable. At that point you might find your existing tools/knowledge insufficient and start asking questions on the forum about such advanced topics.

It also doesn't help that advanced questions, while fewer in number, tend to be quite subtle and evoke a lot of discussion, and so they are visible in the forum a lot longer. The intermediate questions don't tend to be seen as much because they're resolved reasonably quickly, even if they are more numerous than the advanced ones.

I'm not going to lie and say Rust isn't a complex language, but I'd argue the social element is an equally significant factor in what you are seeing.

7 Likes

Couldn't agree with you more.
I'm slowly advancing through The Book and 'Traits' chapter took me three days to grok. Implementing generics with trait bounds combined with borrow checker are by far the most difficult concepts to understand. I feel like on a conceptual level I get it, but it's very hard to reason about it as I write the code. Maybe because I come from a dynamic languages background.
However, rust has brought back my inner curiosity and eagerness to learn and that is the most rewarding thing, knowledge of rust language is a cherry on top.
You're not alone, mate.
Cheers.

1 Like

Rust offers a great deal of power, but also provides a great deal of security. In order to do both at once requires a lot of syntax to express ideas that other languages can't do, which can certainly seem hard at first. That is, it's sometimes difficult to see the difference between "something I want the language to do that I can't figure out how to put into compiling code" and "something I want the language to do that's impossible" without a good mental model of what the language is doing (and practice).

1 Like

I don't think Rust is particularly hard, but there is quite a lot to learn. I had some kind of mental block with lifetime parameters, but I just coded a struct which uses one and now I think I am over that hurdle, hopefully. What disturbs me a bit is having an identifier that doesn't seem to mean anything.

Besides that, I still typically don't know in advance when I need to put in a * or & or &mut, but the compiler puts me right! Macros are still a mystery area for me, I am pretty unclear how they work or what they can do, and whether I should be defining my own macros or not.

Mostly I think it's a matter of writing code, the more you write, the more minor obstacles you overcome and the more proficient you become. I am about two weeks in.

1 Like

Most of the difficulty in Rust is opt-in to get that last bit of performance. If you stick to lifetime elision-compatible function signatures, and do a bit more .clone() and Arc than might be theoretically optimal, then things aren't that difficult.

But as always, the downside of powerful tools is that they can make complicated things.

2 Likes

I was contemplating that very fact today as I stood back and admired my latest Rust creation. A couple of thousand lines of code. It reads binary data from a NATS server, it parses the horrible binary message format therein into message structures, it creates JSON from those and publishes it back to NATS. It's multi-threaded, handling any number of streams as they come and go. Not rocket science but still.

I realized that I had achieved all that without ever needing to write a single lifetime tick mark. No generics, no macros, not even traits or iterators, nothing weird at all. Except that it is async using tokio.

I suspect anyone familiar with languages like C/C++, Java, C#, Javascript would have no difficulty reading that and making a good guess at what is going on. Even if they might have a hard time modifying it before becoming familiar with the type system and the borrow checker.

In fact I think I would be happy to forever keep all the "line noise" of the generics/trait bounds/lifetime syntax out of my application level code.

Of course there is a ton of all that in the dozens of crates I am using. But that is rather like the node.js developer depending on a ton of C++ in his language run-time and node modules.

Now admittedly I have a handful of "clone"s in there, but I don't believe they are impacting performance significantly.

In short, one should not be blinded by all of Rust's features and capabilities, just get on and write your code!

5 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.