Background for Rust Learning

Hi Community

Can you please help me fill in the blank ?

" If you are already familiar with ______ Programming language. It will be easy for you to pick up Rust Language and its syntax.?

Would you recommend someone who is willing to learn to program to start with Rust ?

I don't think such a language exists. Rust pulls a lot from C++ and OCaml/Haskell, so knowing those would help quite a bit, but no language can really prepare you for the borrow checker which tends to be the hardest part of learning Rust. That said, jump right in! The book and Rust by example are fantastic books, if you ever need help, just ask on these forums and you'll get help from either me or the many other people waiting to answer questions here :slight_smile: .

4 Likes

I would rephrase the question as, "If you are already familiar, where familiar means you've built some non-trivial applications with those languages, with ____ number of programming languages, it will be relatively easy for you to pick up Rust, but, you can still learn Rust even if it is your first programming language."

Where I think the blank would be 2 or 3. I do, however, believe learning Rust as your first programming language is possible and useful (I could be wrong though).

4 Likes

The word I would put in the blank is "any".

Why do I think so? Because a million years ago I was first introduced to programming with BASIC. In that same course we were also taught assembler. That went fairly well. A couple of years later I taught myself some ALGOL as best I could in university, I was not studying CS. How different could those three be? In the modern world that would be like someone starting out programming in Javascript, getting into assembler and then finding Rust.

I would not put so much emphasis on syntax. At root all programming is the same concepts, sequence, selection and iteration. Once you are happy with the idea of variables and expressions, but that is something you should be reasonably happy with after high school algebra.

That is something I have been wondering about. It's hard to remember what it was like when being introduced to programming for the first time (with BASIC). Apart from generally being impressed and inspired that machines could even do those things.

But I suspect that with sensible instruction a raw beginner could be taught all the things we were taught in that first year of BASIC but in Rust. There is probably no reason to blow a beginners mind with traits and macros and complex lifetime juggling.

It would require having a lot of seriously simplified tutorial and documentation material available for such raw beginners. Throwing them into the Rust documentation would be hopeless.

1 Like

Yes. In a way, it's probably easier that way.

Added bonus, if you become fluent in Rust and then use a language that doesn't have a borrow checker you'll be all like "Wait, so in other languages everything is implicitly in an unsafe block?" and we'll be all like "Hey, that's a neat way to put it, why didn't we think of that?!".

But seriously; in the university I had friends who had much easier time to learn object-oriented programming than I had when I started with OOP in C++, because they came to it without any preconceived ideas about what programming should look like.

2 Likes

Ha! Wow. That sounds exactly like the reaction I had to C when I was first trying to use it in 1982 after having learned in BASIC and done some ALGOL.

After scratching my head wondering why my programs were crashing out and/or hanging up the whole machine many times I even asked a member of the team "Is it really possible that a high level language just crashes and dies without any indication of why?" He looked at me like I was an idiot. But it was a reasonable assumption of me that an HLL would not, given the BASIC and ALGOL experience. I could not believe it.

Luckily I had done a lot of assembler and the penny dropped that C allowed me to hang myself in the same ways.

3 Likes

As @RustyYato had mentioned, Rust took inspiration from various languages like C, Ocaml/Haskell, and Ruby.

Personally, my experience in C/C++ is very limited, but I've had quite a bit of experience in functional languages like Ocaml, which really helped me understand concepts like variant types and pattern-matching.

It might just be me, but before I learned Ocaml, Rust was way to tough for me. I was already writing fluent Python and Go at the time. But again, the language has evolved so fast that today credits should be given to the compiler's error messages that are almost always accurate enough to just blindly follow them most of the time and learn from that.

1 Like

Skip to the end for a TL; DR.

Once again, I have to mention how I got into Rust.

I've been writing C and C++ for several years before encountering Rust, most of which was in the "modern" dialects (C++11 and onward). My journey in these languages was basically a continuous quest for best practices, patterns, and tools for achieving memory safety, if only partially.

Rust's ownership and borrowing system was basically nothing new to me, insofar as the coding style and the underlying mental model are concerned. The only thing about borrow checking that genuinely surprised me is that it's at all possible to do it statically and automatically. The patterns and best practices I learned in C++ with regards to memory management remained by and large identical in Rust, and this part of the language didn't have a steep learning curve for me, if any.

Knowing an ML-style, statically-typed functional language helps too, mainly for understanding how not to use inheritance for absolutely everything, and for getting the hang of traits.

One other important thing that is not tied to any one programming language is knowing a thing or two about compiler implementation. Understanding how objects are laid out in memory, how the call stack works, and low-level details like this help a lot with intuitively grasping why certain things are not possible or very hard to do in a close-to-the-metal language.

TL;DR: I'd perhaps fill in the blank with "Knowing C++ and Haskell, and having been exposed to a basic compilers course will help you a lot with learning Rust".

2 Likes

When I was a graduate student teaching astronomy to science majors in 1970, the goto (pun intended) language for technical work was Fortran. The problem of using it to teach programming to people who had barely heard of computers was the cruft. It's a compiled language, so you had to learn a lot of steps just to print "Hello, world."

The only scripting language available on campus was Basic, so we started the students with that. After they became familiar with the concepts of variables, expressions, and debugging, we switched them to Fortran. That worked far better than when we tried starting them off with Fortran.

I firmly believe that a scripting language is the best way to get started with programming. If nothing else, having a REPL (read-eval-print-loop) is great for learning. Rust is my 16th language, but I used repl.it a lot when getting started.

2 Likes

Heh, I kinda expected you to show up :). I would argue that your experience is rather unique, as you really got to know C++ over quite a long time. This is a bit removed from the experience of people asking for advice on how to learn Rust, or what languages would help in learning Rust.

This part in particular exudes experience that the I wouldn't expect someone asking for advice on how to learn a language to have. Also, I wouldn't recommend C++ and Haskell as prerequisites for Rust, so I may have downplayed their usefulness a bit too much.

But this is off topic. It's always nice to read about how you got into Rust.

1 Like

Yes, but, with Rustup, Cargo, etc. the gory details are pretty hidden and you can do "Hello World!" pretty with a few simple commands. Then, from there, you can get into ALL the coding introductory material without worrying about borrow checking pretty quickly and they don't need to really learn any of the details of how the compiler/cargo works that much. Also, with VSCode and Rust Analyzer coupled with CodeLLDB you can easily show them how to edit, build, test, and debug code at the level they need without a lot of gory details.

1 Like

I agree with everything you say. Some parts of the world have actually improved in the last 50 years.

Nevertheless, I still believe that being able to type a few lines on the console, hit Enter, and see the result speeds learning for new programmers. The Rust playground does come close, but borrow check errors get in the way of learning the basics, such as how to write a loop.

1 Like

Thanks Folks for your Reviews and Inputs on my Question. Really appreciate it !! I wanted to mention everyone but newbies are not allowed more than 2

I looked up a sample code for Taking an Input and output and it seemed complicated given same things with C/C++ or basic /Python. Yes, Borrow checker is something worth learning .

   fn main() {
        use std::io::{stdin,stdout,Write};
        let mut s=String::new();
        print!("Please enter some text: ");
        let _=stdout().flush();
        stdin().read_line(&mut s).expect("Did not enter a correct string");
        if let Some('\n')=s.chars().next_back() {
            s.pop();
        }
        if let Some('\r')=s.chars().next_back() {
            s.pop();
        }
        println!("You typed: {}",s);

Rust Journey is going to be interesting . Rust by Example is a Good Place to start .

Thanks again !!!
Vaibhav

Apparently I'm misunderstanding something here. To me, this is exactly what was being asked: "knowing what language helps you learn Rust?" – and in my experience, it is plainly and simply the case that "knowing C++ and Haskell helps a tremendous amount in learning Rust". That's because only the surface syntax and other technicalities (dependency management, coding style, naming conventions, etc.) are left, and I don't have to re-work my whole intuition and mental model about objects and lifetimes and values and memory management.

Of course, for those who don't find the memory model to be the hardest part to learn, other languages may help more. For instance, if someone finds dependency management to be a pain but is able to learn borrowck in a day without previous exposure, then JavaScript and the npm ecosystem might help this person understand better the parts s/he finds difficult. Everyone might find different parts of the language easy or hard to learn.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.