Is Rust-Lang hard for a beginner?

Some people do not have same requirements and project needs like you do. Rust is not holy grail for every IT area, but it seems to be closer than other languages for some of the "niches"... :slight_smile:

4 Likes

Yes. Rust is hard for a beginner. With the release of julia 1.9, I would recommend programming beginner to learn julia and do something interesting and useful. If anything not satisfactory then I would recommend rust.

Some people are very confident in asserting that: "Rust is a hard language for the complete programming beginner." Mostly this claim comes without any supporting evidence.

I can accept that Rust is not the simplest programming language on the block. It's likely that some people with experience of other languages have difficulty in unlearning/relearning. It's likely that some people have difficulty because something the are used to using is not well supported in Rust. None of this says anything about how well, or badly, Rust could be used to teach programming to rank beginners.

No, what we need is evidence. We need some school or bootcamp or whatever to teach programming to a bunch of non-programmers with Rust. Say high school age kids. With teaching material targeted at those who know nothing about programming.

We can only ever resolve this recurring question with such an effort and observation of how well it goes.

Surely there must be someone out there who has done this or is planning to..maybe...

Anyway, my feeling is that: Yes is Rust is not a simple language. But I feel one could go a very long way in teaching programming from scratch without having to worry about complexities of reference lifetimes, lifetime annotations, generics, macros etc. As one would in BASIC or Javascript or whatever.

Then of course, when one has brought ones students that "very long way" in Rust introducing the more complex things will come naturally.

5 Likes

After the C/C++ group was already split in an answer above, I would also like to suggest to split the GC-language group. Maybe even threefold:

  • people most familiar only with dynamically typed (imperative, GC’d) languages, i.e. those languages where everything is shared and mutable (and untyped), and thus usually single-threaded and full of run-time exceptions – think Python or Javascript, but probably lots more I’m not so familiar with
  • people well familiar with strongly typed imperative languages, ideally even offering more complex type system features like generics or interfaces – think e.g. Java or C#, or Go, and again lots more
  • people well familiar with (strongly typed) functional programming languages – for example Haskell, but probably also lots of MLs; even a Lisp may help (although at that point, people might have also simply proven they can easily adapt to just about any level of novelty in a language)

I believe that people used to strongly typed languages will have a significantly easier time getting into Rust, as that gives you familiarity with one of the major differences between Rust and those languages where everything is interpreted and happens at run-time (and commonly way more things are “allowed” than should be). Given that most learning material for Rust does fairly quickly introduce most of the important Rust language features, I can only imagine how challenging it might be to familiarize yourself with the concept of interacting with a compiler and compilation errors, and to really reason about types, whilst possibly/probably already stumbling into traits and lifetimes at the same time.

Also, languages like Java will have generics and interfaces, which helps with some concepts of Rust’s type system, naturally; and such a language also typically offers multi-threading, so concept like thread-safety should be familiar.

Functional programming was what I was most familiar with, going into Rust, though I also did a lot of Java in Uni, and learned some rudimentary C++; so I’m actually least familiar with those dynamic languages like Python, Javascript, etc… and to this date I do not feel like I have missed out on anything that would have helped me learn Rust more easily (which also makes me question the suggestion to e.g. “learn Python(just an example) first” if the stated goal is to learn programming and Rust in particular, apart perhaps from the fact that such a language will have better beginner learning material for programming in general, and you will still learn what a variable or a for-loop, or indexing, recursion, etc… is. So I’m not saying it’s use-less, I’m just saying that, in my opinion, such languages are about as different from Rust as you can get – so, maybe it’s more difficult than necessary, but hey, at least you’ll have seen a great spectrum afterwards? Anyways… with the above-mentioned background, I felt like I had about as good a preparation for Rust as one could get, and my learning experience was relatively straightforward, as I mostly only had to learn the language features of Rust that are unique to Rust. (I.e. for the most part, the Ownership and Borrowing system.)

So functional programming familiarity will usually come with even more familiarity with good type systems; furthermore you’ll have seen algebraic data types and pattern matching; and presumably also (the equivalent of) the trait system. And with functional programming, one is used to working with restrictions; even stronger restrictions than “no shared mutability” actually, since (at least pure) functional programming involves the practice of working within the constraint “no mutability” instead.

Of course you can also not actually apply many of the idioms of functional programming directly; e.g. Rust does not offer tail calls, so the typical functional recursive algorithm style does not actually transfer very well, even if you want to; (at least in general; of course, e.g. traversing tree-shaped data structures will usually also involve recursion in Rust). But then again, do people deeply familiar with a functional PL actually exist who haven’t had at least some exposure to imperative programming as well?

6 Likes

Rust is only hard if you want to use advanced features such as generic types, closures, async or multi-threading.

Without such advanced features, Rust is easy and if you make a mistake, the compiler will tell you how to do it correctly.

Actually, multi-threading is very easy unless you want to have your threads communicate with each other.

3 Likes

This is basically what Linus Torvalds once famously mentioned

C++ is a horrible language. It's made more horrible by the fact that a lot
of substandard programmers use it, to the point where it's much much
easier to generate total and utter crap with it.

While the original statement is of course very polarizing, I believe this is exactly what he was referring to.

Bjarne Stroustrup also famously said:

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off

I would say that Rust makes it almost impossible to shoot yourself in the foot. To do so you need to make an active choice and it will not happen randomly.

I first learned C++ before being introduced to Rust. I come from a mathematical background and thus most of the concepts were not hard to pick up. Working with lifetimes can be challenging sometimes but I tend to always find good working solutions for my problems. To me, Rust is a breath of fresh air compared to the aging and bloated C++.

6 Likes

I wouldn't put it so strongly. Rust has plenty of ways to shoot yourself in the foot, it's just of a different nature than in C++. In particular, if you create some program or library with some carefully considered high-level structure, then a change to the requirements is more likely to force you to totally rebuild that structure from the bottom up. Contrast between how C++ and GC'd languages let you copy around pointers/references at will, vs. how idiomatic Rust requires you to have a single owner pinned in memory and only writable from one place at a time. If you design around some particular owner and it isn't flexible enough, then you're going to have a rough time. This can be worked around with Rc/RefCell, but it's far from ergonomic.

Another issue, apart from inflexible ownership, is inflexible lifetimes, when people use the right owner but the wrong lifetimes for their task. On a small scale, this can be seen all the time, when people build a library but can't even get its initial use case to work. It's a common complaint that "I wrote all these types and functions, but then when I tried to use them I ended up with a lifetime error, and now I'm randomly modifying all my lifetimes up and down the stack trying to get it to compile." Often, this is accompanied by a rogue &'a mut self somewhere, or an attempt at a self-referential type, without understanding the issues around them.

Another big time waster (that I have known to ensnare at least 3 different people so far) is trying to write a function accepting a lifetime-generic async closure. That often appears to nearly work, but it never does work, and you'll end up in trait hell if you try.

8 Likes

That is exactly my point. Many more problems (as you rightfully pointed out) occur during the compilation process rather than run-time. This is supportive of my statement since after all, code which we do not run can not really harm us. Shooting yourself in the foot is shifted to a development problem rather than a user problem (which also includes library users ofc).

I think Rust is hard for seniors too. Especially for OOP developers. Because brain is stuck on OOP paradigm. Rust doesn't support inheritence. Because of that some topics are difficult to understand and getting used to.

4 Likes

Well, speaking as someone who is, basically, learning Rust as a first language, the learning curve is very, very steep. It has been a real struggle to work through learning the Rust language. I have to agree with the statement made by someone in a previous post to this topic -- the problem is perhaps rooted in the lack of learning guides written for a true beginner. I have been relying mostly on The Book and the biggest issue with that (really well done) document is that the writers simply seem to be absolutely unable to look past their own knowledge level. They make assumptions about previous knowledge they consider basic to the background of their readers. When you are coming in cold, that basic knowledge just isn't there and so confusion results. I have come to rely a lot on the people who post on this forum for help. Without that help, I don't think I would have made any progress at all. One other complaint I have about the The Book is the lack of very many small exercises to help solidify the concept/technique being taught. There are a few, just not enough. (I had to make up my own and then I didn't have anything to compare with to see if my work was decent.)

Clarification: I'm not a complete beginner. I started with Fortran (using punchcards) in the 1970's, then taught myself Basic (using paper tape) and later learned C using the Mix C compiler. I never progressed to the point that I was writing robust code and eventually gave it up entirely. Now, decades later, I have been taking up coding again in my attempt to learn Rust.

7 Likes

Agreed. As great as the book is, it is not ideal for Rust beginners (i.e., people not familiar with many of the Rust concepts).
I found the book Beginning Rust by Carlo Milanesi to be much more appropriate for a beginner. Strongly recommended.

2 Likes

Hello,
Thank you so much for your reply.
Yes, I guess this book is a great book for the beginners like me.

I personally believe that I have extensive experience in Dart, TypeScript, C++, C, and ActionScript development. While I may not be proficient in C++, I find it a bit challenging to learn Rust on my own, especially considering the various difficulties I encounter every day. However, since the introduction of ChatGPT, learning Rust has become much easier for me.

I don't speak kafta, but it should have some form of "C" library bindings. If it can be called from "C" then it can be called from Rust. If it can not be called from "C" then is is not a good library.

Kafka is written in Java (and Scala I believe). Basically a JVM thing.

However one would expect it is possible to write Kafka clients in any language. Or that there are Kafka client libraries with C bindings.

Other however, if the Kafka protocol relies on pushing Java code (or byte code) up the wire that could be a show stopping problem.

I have no idea really, we use NATS in situations where people use Kafka. The NATS Rust client works very well.

The native wire protocol for Kafka seems to be well-documented and straightforward to implement, with the hard part being that Kafka is a distributed system where you need to implement support for multiple servers, not all of which may be available at a particular time. There’s nothing Java-specific about it.

That said, I’ve only used Kafka at work from a very limited runtime environment (sandboxed RhinoJS) using Kafka’s REST proxy with plain HTTPS requests, and it’s been fine, just a bit more Base64 than I would have expected from a JSON-based protocol. I’d suggest that having a nice HTTPS interface is part of the reason why there isn’t a clear leader in native Rust implementations.

I went through the git of nats --here they don't mention they support kaka. My systems are all written around Kafka and I need Rust to speak to Kafka.

By the way, the Kafka client doesn't push any bytecode on the wire. We do have rd-Kafka that works. the only point is no forum support or proper tutorial.

Sorry, I did not mean to imply that NATS worked with Kafka. Only that NATS is a distributed messaging system that can be used in place of Kafka to do many of the things one might do with Kafka.

We chose NATS over Kafka because it suits our messaging needs, it is very simple to install and use, the NATS team supports Rust as well as many other languages, it performs very well. The fact that it has nothing to do with Java or the JVM is a bonus :slight_smile:

Sounds like you are stuck with Kafka. Oddly enough in my 4 decades experience I have never seen a company use Kafka. I'm sure with your 16 years experience you will be able to work it out.

3 Likes

This is an alternative to Rust book, is there an alternative to Rust reference?

1 Like

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.