Is Rust-Lang hard for a beginner?

Hello,
I need the opinion of those who have not had much knowledge in programming, because I want to know, is Rust-Lang hard for a beginner?

Any idea welcome.

Thank you.

1 Like

I think it is in practice hard for a beginner.

I feel like if there was better material targeted for beginners, it could be easier than it is, though.

5 Likes

Computer programming is a hard skill to learn in general, and using Rust as a learning language may very well be harder than most. Despite this, I believe that Rust may still be a good language for a beginner to learn with.

Most of what makes Rust relatively hard is that the compiler is less forgiving of errors than other programming languages, so that a program that Rust accepts is more likely to be correct than a program that simply compiles/runs written in another language. As debugging odd behavior is one of the hardest, most frustrating, tasks in programming, the extra difficulty of Rust may actually be a net positive for novice programmers.

Rust is also quite opinionated on how you can solve certain common problems. These mostly align with best practices in other programming languages— The habits you'll learn from Rust will help you to write more reliable programs when you eventually move to another language.

NB: I've been a programmer for a long time, so this is more speculation on my part than speaking from personal experience.

14 Likes

I do not want to presume why you are asking this question, but you might want to read through Easy Rust because it should answer your question.

It is a book that teaches Rust with everyday "simple English". Its main target audience is people who are not native English speakers, but I find that it actually does a decent job teaching Rust as a first programming language. For example, it defines what a comment is!

As a bonus, each chapter comes with a 5-10 minute video, so you can follow along with a video tutorial at your own pace if you prefer.

So, I would say; no! Rust is not hard to learn for a beginner. You just need a gentle introduction to build up the lexicon necessary to write code. Also, echoing The Rustacean Cycle: Learn, Teach, Deliver - Nell Shamrell-Harrington:

What is a Rustacean?

Anyone who has an interest in Rust

At any level and in any role

11 Likes

I think Rust could work very well for a first time ever student of programming. After all the very first thing people will experience is a "hello world" program which is pretty straight forward in Rust:

fn main() {
    println!("Hello World!");
}

There is only a few concepts beyond actual printing that need to be glossed over in this first lesson, What is fn? What is main(){...}? What is that ! for? But compare that to "hello world" in C or Java. Arguably Rust's "hello world" is more concept heavy than that of Javascript, Python, BASIC etc but still pretty good.

After that one can move on to the notion of variables, expressions, sequences, conditionals, loops etc. After all it is said that all of programming is only "sequence", "selection" and "iteration". I would argue that all of that can be taught in Rust as easily as any other language.

Then one can get on to imparting notions of functions, parameters, returned values etc. Then structures, methods, traits,... slowly, slowly step by step.

One can get a long way in Rust before bumping into complexities of lifetimes, generics, macros and so on.

Meanwhile, while doing all that Rust makes it very easy to build and run ones first programs with "cargo". Contrast to building and running "hello world" in C or C++. And the compiler produces very nice error messages.

The problem may be the lack of books, tutorials etc that are targeted at the complete programming beginner. Suggestions above indicate that issue is being resolved. I have not looked so cannot comment.

It would be great if "hack3rcon" would dive into Rust as a programming beginner. Taking up the suggestions above. Then we could see how well such a beginner gets on.

4 Likes

As a counterpoint, I'd say that Rust throws learners in at the deep end. Even the archetypal basic program throws a lot at you when println is not only not a function, but immediately does things real functions are not capable of doing, i.e. being variadic. You can of course handwave this and pretend it is a function or otherwise magic until you have context for understanding macros, but this is still quite a distinction from say, C where printf is complicated but is nonetheless working by the normal language rules.

Additionally, while you can conceptually unpack all of the relevant concepts that make up Rust like the syntax constructs, types, functions, etc, I think a beginner actually trying to write practical code will rapidly run into "circular dependencies" in their understanding because even very basic standard library functions touch on many concepts at once. As an example, look at the documentation for str::find and you'll see

  1. the method itself is generic, over two different kinds of variables
  2. knowing how to get hold of a Pattern to pass involves understanding traits
  3. the return type is a third use of generics, this time instantiating a concrete type rather than quantifying
  4. and actually getting the value out without blindly unwraping requires understanding how enums work

The corresponding C function is still not beginner-friendly (since it's dealing with pointers) but defining and using it has fewer underlying concepts - both parameters and the return value are of the same (concrete) type, and the error case can be checked with the normal ==. Someone trying to practice with the language who doesn't necessarily have anyone to directly answer their questions will likely bounce off the former in incomprehension much harder than the latter.

That said, I think Rust can still be good for beginners who can perservere through needing a comparatively large understanding to get going, because the compiler's feedback is much more valuable than in C-likes. Having a C program crash and burn for no obvious reason can be very disheartening, and rustc is extremely good at pre-emptively stopping you doing the wrong thing, which is IMO critical if you have yet to learn why it's wrong or what the consequences are. Rapid feedback and diagnostics are needed for learning.

OTOH, languages like Java/Python/Javascript present a much simpler model of how the machine works compared to Rust, and so might be easier as an entry point to programming in general - you simply don't need to know about issues like ownership, lifetimes, destructors, etc, to learn how to write code. However, you do need to know these things at some point, and the converse is that once you do learn the comparatively large amount of things going into Rust, you are prepared for every other language you might encounter in the mainstream save Haskell.

5 Likes

I believe it is very useful to have programmed in C (not necessarily C++) to appreciate the features Rust provides. However, that does not mean that I believe, everyone should be programming in C or Rust either.

I think that programming languages serve purposes first and foremost. Rust seems to be applicable in many cases but other languages might be better suited in a given context due to either more resources or possible collaborators already working with said technology. Of course, this is a silly argument in the long run since the current trajectory of Rust will potentially outshine many other programming languages. So if you are curious, and simply want to learn and prepare yourself for the future, Rust is a good start.

If you have a certain purpose why to learn a language or how to program in general, I would much more consider which languages have already been used to implement present technology. For example, HPC (High Performance Computing) in Rust is possible, but some otherwise present tools are still in early stages or simply missing.

1 Like

I wonder if, paradoxically, it is easier to learn Rust as a beginner, since you don't have to unlearn things from other languages that don't translate as well.

I know that, personally, coming from mostly Garbage Collected languages, I had to change a lot of my patterns when I started writing Rust.

Edit: I guess my point is, I wonder if, if your goal is to eventually write Rust, you might cause yourself problems by learning certain languages first.

5 Likes

As a counterargument, Chapter 2 in The Book walks the reader through writing a 35-line guessing game that covers:

  • Printing to the terminal
  • Reading from stdin
  • Parsing strings to numbers
  • Enum basics
  • Control flow with loop, continue, match, and even a panic

All without mentioning traits. This game is very simple, but I would still call it practical code.

Speaking of str::find, the JavaScript equivalent accepts "a regular expression, or any object that has a Symbol.search method." With an implicit fallback to constructing a RegExp from the arg. So, you need to understand what a regular expression is (or at least how to write one) or figure out what a Symbol is or how to use any of the magic that it provides.

You can mostly gloss over it by passing a string to the search method and the implicit RegExp conversion will usually do what you expect [1]. But when that doesn't do what you expect, welcome to RegExp fun! All while String.prototype.indexOf is probably good enough... except even this method still has string coercion rules on its argument!

This is all silly of course. But what I'm demonstrating is an example of the observation made by Richard Feynman that "everything is interesting if you go into it deeply enough."

This completely ignores all of the peculiarities of those languages, such as the previously mentioned JavaScript string coercion rules and several other humorous things you can do with the language, many of which you'll unfortunately run into completely by accident. Python and Java have their own "wat"s. And for completeness, so does Rust!


Throwing aside all the ways you can write bugs, I still don't see anything that really sticks out as a showstopper for anyone who wants to learn Rust as a first programming language. You have to remember, these are fresh, malleable minds that aren't coming to the language with bias or preexisting expectations from experience with other languages. In many ways, those biases are why many Rust skeptics won't even give it a try.


  1. Just like you can mostly gloss over the method signature details of str::find and just pass a string slice to it! ↩︎

4 Likes

Speaking from speculation, as I have been programming for some years now:

Personally, I would not suggest starting with Rust as a first programming language to learn. It front-loads a lot of inter-dependent concepts. Many of Rust's unique features are meant for solving problems, where you might not even understand why it's a problem unless you have tried a language without that feature. My suggestion would be to start with Python or JavaScript, then C, and only after that Rust. That being said, there is no one "right" way to learn programming.

3 Likes

I feel Rust is much more forgiving than C or C++ for beginners. It's quite easy to write programs in the latter which are UB ridden yet compile with no errors or even warnings with the default compiler invocation, at which point you have to start debugging a program that crashes at runtime -- or worse, runs to completion but produces garbage or acts unpredictably in other ways.

12 Likes

Rust's protections are the reason why I think it's good to have some exposure to C first. Once you have felt the pain of segfaults firsthand, you are better equipped to understand exactly what the borrow checker is protecting you from, and why it yells at you when it does. I think it's good to learn a duck-typed dynamic language first for a similar reason—after having spent time struggling with runtime type errors, you will understand why the static typing rules exist.

3 Likes

You want to cause pain to your new students? That does not sound like a great way to introduce anyone to any subject.

I recall my experience of learning C some time after I had been introduced to programming with BASIC and assembler and then using Algol. I was shocked at how sloppy C was. Seemed it would compile almost anything my fumbling experiments created, and then produce mysterious wrong results at random or crash without explanation, often totally hanging the PC I was working on requiring a reboot. Very frustrating. I would not say C was a good beginner language.

I think anyone with a high school education (or pretty much anyone) understands it makes no sense to perform addition on different things, that "10 seconds + 5 kilos" is a no-no for example. Therefor I don't think strict type checking is an issue for a beginner to programming, it's natural.

5 Likes

I would make an analogy to going to the playground as a kid. It's fun, there is lots of freedom to jump around, climb on stuff, go try things and experiment (programming analogy: compiler not yelling at you every second). It can be painful; at some point, you will probably scrape your knee, get a boo-boo, cry to your parents (programming analogy: runtime errors, segfaults). But the danger is strictly limited, the ground is covered in a soft material and adults are watching out (programming analogy: your first toy project is not mission-critical). Result: you have fun, and the experience prepares you for more serious stuff later on.

Also, I did not suggest C as a first beginner language; it should be a second or third language at least, preceded by something like Python or JavaScript (though BASIC works too, I suppose).

4 Likes

Java/Python/JS don't present a model of how the machine works. They present a model of how black magic works.

When programming in these languages, there is:

  • resource management that you are not supposed to understand or question (let alone override);
  • pervasive shared mutability that appears to "work", until it doesn't (I had "senior" programmer friends ask me questions about Python lists changing unexpectedly, until I pointed out that assignment doesn't deep-copy);
  • fully dynamically typed collections in the latter two languages that also appear to work, until the overhead associated with automatic boxing and impossible-to-opt-out dynamic dispatch becomes too high and you can't do anything about it;
  • multi-threading in Python that also appears to work, until you find out it doesn't, because there's this thing called The GIL, which pins your carefully threaded code to exactly one core, making it borderline useless.

And when you hit these limitations, and want to understand or – horribile dictu – optimize your code, now you have to understand not only the machine, but also the many layers of opaque abstraction on top (garbage collection, the GIL, dynamic dispatch, virtual machines).

Not to mention debugging, which is like 99% compile-time in Rust, and 99% run-time in the cited languages.

I think "my code compiles faster" is not a very good measure of how easy a language is. Rust forces you to understand upfront what you are doing, which is why your code is harder to bring into a compile-able shape. (At least while you are a beginner. I have no issues writing Rust code that compiles after the first few trivial errors, or even on the first try.)

In contrast, many other languages paint a deceptive picture of complexity. They hide complexity and apply defaults that are not universally meaningful. And then, when you already bought in, comes the surprise complexity, which is going to be much more painful to handle than choosing the right tools from the get-go would have been.


Finally, as to answer the question in the title of the OP:

Is Rust hard for a beginner?

It may well be. Because what isn't hard for a beginner?

12 Likes

After about 20+ years in IT, and having fun with several languages like C (10+y), C++ (5+y), some junior level Java. Currently (several years and pending) on running projects: Python, JS/TS, Rust...

I don't have experience of passing the rust knowledge to others, but my current belief is, it's not hard at all, unless "rust beginner" comes in with pre-built mental model/expectations from other languages.

IMHO it could be as good choice as any other, assuming the teacher/guide/tutorial used to learn does not pass/force the mental model affected by C/other languages (and this IS hard!).

5 Likes

I feel like a lot of teaching material (generally speaking) targets experienced users from other contexts. :confused:

A good (i.e. bad) example – unrelated to Rust – is web.dev, which seems great for someone like me who did HTML in the late 90s and 2000s, but bad for someone who newly gets into HTML. At least I made that experience.

All analogies are flawed but I will go with yours a bit.

When our beginner programmer (Kid in playground) is playing around with programming and a programming language for the first time it can be frustrating and time sinking when mistakes are made and have to be investigated (scrape your knee, get a boo-boo, cry to your parents).

In the end both are hopefully safe the play ground is padded, the program can be restarted. No harm done.

My question then is where should our beginner programmer feel the pain? Is it when things produce random results and crashes at run time. Or is it when the compiler spits out errors at compile time?

I would argue that for a beginner the latter is preferable. Why? Because run time failures drag one into the pain of debuggers and debugging at a time when our beginner is not really experienced enough to know what they are looking at and is struggling with the concepts of the language enough already and needs no further burden. Or our beginner has to start writing tests which is a drag, that can come later.

Conversely, getting the pain at compile time with error messages and helpful suggestions is related to the code one has written at that moment. Much less friction.

5 Likes

Yesterday’s novelty can become tomorrows normal. While for most of us, learning Rust includes some significant appreciation for what pains it avoids and what it makes better than (or what good things it adapts from) other programming languages, and this appreciation of why Rust “feels better” might be an integral part of our learning experience or our view of the language, I believe, assuming the language (or at least its kind of feature-set) catch on in the mainstream sufficiently, and for long enough, then it won’t take long until it feels just natural, just the way modern programming languages are supposed to be, and something that will of course also be taught to beginners, and for a good number of them as a first language.

After all, nowadays, it isn’t the case either that every beginner must experience the inconvenience of assembly before learning higher-level languages; the inconvenience of goto-based languages before using something more structured; the challenges of (unsafe) low-level languages before trying something higher-level (i.e. people recommend Python before C, not after); the troubles of simple plain (ultra-)minimal text editors before using something with automatic indentation, syntax highlighting, and/or other IDE functionality, etc…

There is an argument to be had that Rust isn’t the best language as a first programming language, at least depending on the type of approach you’re after or course you’re designing; something less feature-rich might be nicer; perhaps even (partially) toy/education languages. For example, my university used to use Racket (a version of Scheme, i.e. a Lisp) for their first programming course, and I liked the principled and from-zero approach that that allowed. Furthermore, a functional-programming(-ish) basis is, in my opinion, a very good foundation for going into Rust (if that’s the ultimate goal), because it shared some values, like avoiding shared mutability (by avoiding mutability in general), or typically having more of a value-type image of data instead of a (shared-mutable) object-based image of everything there is.

I don’t know whether there actually is any benefit to using other languages, compared to the possibilities of staying within Rust, and working with learning materials and libraries designed for programming learning beginners, but with “real” Rust; and that’s not least because I have never seen such a course or material for beginners based in Rust.

6 Likes

I definitely agree with this. "What error is the compiler giving?" is such a common first response to questions here, and for good reason.

And the FP vs. OO divide is why I think Rust would be a great first language. It is neither fully functional nor fully object-oriented, but the ownership model encourages a happy middle ground with the best practices from both.

Probably because I came to Rust from several years of (mostly OO) Python, I have frequently found myself approaching problems from a certain (very struct-first) point of view. But I feel the best progress I've made in learning Rust has typically come when I finally manage to see whatever problem I'm having from an alternate perspective.

1 Like