Ask HN: How to Learn Rust

I am trying to learn Rust few weeks, but it seems to me a very hard language, to be honest, I never thought only learning a language will be this hard. I am following books and few youtube tutorials. Any suggestions?

65 points | by fuadnafiz98 1308 days ago

14 comments

  • techjuice 1308 days ago
    Find one high quality resource, stick with it and finish it all the way through.

    I recommend starting with the developer documentation so you can understand the language before anything else. This is normally what I do when starting to learn programming languages, especially when languages first come out.

    Learn Rust https://www.rust-lang.org/learn

    Learn ARM Assembly https://developer.arm.com/documentation/dui0473/m/writing-ar...

    Learn Go https://golang.org/doc/

    Learn x86_64 Assembly https://software.intel.com/content/www/us/en/develop/article...

    • fuadnafiz98 1308 days ago
      assembly :(
      • flohofwoe 1307 days ago
        There's no need to learn "all the assembly" of a modern processor, just the basic instructions and maybe write a few simple programs to understand what's going on. Even though writing assembly is hardly needed today, being able to read and understand assembly is very valuable for debugging and optimization sessions.
        • renox 1307 days ago
          I'm not so sure, I've been thinking about how to implement a fastest 'very small map' (let's say a maximum of 16 key, with the keys being 2 bytes), but for this I need to learn SIMD x86 assembly language :-(
      • techjuice 1307 days ago
        I've found learning assembly a necessary evil for certain work. I use Rust to automate lifting binaries and conduct protocol analysis to find vulnerabilities. Without knowing assembly it may limit the depth of analysis that can be done.
  • mactavish88 1307 days ago
    I'd recommend:

    1. Identify a few projects you'd like to implement (toy ones if you want, or applications that exist in languages you already know well; or try to implement the Advent of Code problems: https://adventofcode.com/).

    2. Organize them by your perceived difficulty of implementation (Advent of Code is already kinda organized in increasing order of difficulty).

    3. Do your best to implement each project, experimenting with different approaches to architecture, testing, etc.

    Having experience in many other programming languages, there are honestly so many different ways to architect and implement a Rust program compared to other languages (especially if you compare to a language like Go). Also, getting the hang of composition (with or without traits), when you come from other languages, is quite challenging.

    The whole async/await thing is another story entirely. I currently do full-time Rust development and, tbh, I'm not totally convinced that async/await is always better in all situations. I started toying with Rust back in 2018 and have been doing full-time dev for a few months, and I'm still continuously learning new things.

    The great thing about Rust is that it gives you so many options.

    The terrible thing about Rust is that it gives you so many options :-)

    • w4tson 1306 days ago
      This is great advice. This is how I learned. When you’ve completed a puzzle (and not before!) check out how others solved it here https://github.com/Bogdanp/awesome-advent-of-code

      I highly recommend burntsushi’s solutions. They were closer to what I was aiming for: readable & maintainable idiomatic rust.

  • K0nserv 1307 days ago
    1. Read the Rust book[0] front to back. Yes seriously, the whole thing. Rust is different enough from other languages that it makes sense to do this.

    2. Write 1 or more serious rust projects of your own choosing. Aim for projects that’ll be thousands of lines of code.

    3. Read “Programming Rust”[1]

    4. Write more projects

    This is what I did anyway.

    The Rust discord has a beginners channel which is invaluable for asking questions when you get stuck.

    0: https://doc.rust-lang.org/book/

    1: https://www.oreilly.com/library/view/programming-rust-2nd/97...

    • guitarbill 1307 days ago
      This is great advice. Because while the Rust book is good, certainly can't fault it, I hate reading about programming languages. It doesn't work for me. If it does for you, great.

      If not, then just write Rust. Remember: no matter how bad or non-idiomatic the code you write, it's still better than not doing it.

      If you don't have a project you'd like to do, you can port something to Rust. I think a thousand lines is terrific advice. Writing Rust really helped me solidly remember many "how do i do X in rust" things. Crib liberally from other codebases. Ripgrep is perfect for getting inspired with Rust idioms, such a good codebase (obviously don't port that :D).

      I'm at 15k lines now. It gets better! You'll learn to appreciate cargo and the build system. It just works. No more makefiles, pom.xml, requirements.txt. Rust-analyzer is great for IDE hints in a lot of IDEs, but easiest to set up in VSCode. If you end up shipping a CLI program/giving it to friends, you'll appreciate zero-dependency binaries (well, except some libc dep).

      If all those things don't matter to you, then re-evaluate. Programming languages are a tool; nothing more and nothing less. What are you trying to achieve? Honestly, you might be better off spending your time on focussing on your career, no matter what the language. You don't say why you want to learn Rust, so I'm not going to guess. But you don't need to know Rust to be a good programmer. Rust will be there in a few years, too.

    • hackart 1307 days ago
      I am doing the following lab: https://tc.gts3.org/cs3210/2020/spring/lab.html If you are interested in the subject, i think this can be a good first project.
    • fuadnafiz98 1307 days ago
      Thanks for your suggestion :)
  • iscoelho 1307 days ago
    Before learning Rust, I would highly recommend learning C/C++.

    Rust has patterns that are very different from any other language I know of. This is why it comes across as an extremely difficult language. I would say however that C comes very close to having similar patterns (if you have discipline!) partially due to lack of OOP.

    I'd also say that Rust is a poor language to learn multi-threaded programming. You absolutely won't appreciate Rust until you work in a language with no safety & learn the rationale yourself.

    • pornel 1307 days ago
      I had hard time learning Rust, because I knew C.

      C programmers see references as pointers, and then tangle themselves into borrow checking hell, because they try to avoid copying, but actually avoid owning.

  • melling 1308 days ago
    The HN noise on Rust is so deafening that 5 days ago I decided to give it a try myself.

    Here are a couple of links that I have used:

    https://fasterthanli.me/articles/a-half-hour-to-learn-rust

    https://github.com/Dhghomon/easy_rust

    I’m using http://repl.it to learn in the browser.

    My GitHub repo, which will hopefully expand over the next couple of weeks:

    https://github.com/melling/RustHelloWorld

  • PopeDotNinja 1307 days ago
    I haven’t learned Rust yet, but in general I like to pick a tightly scoped, well defined problem & try to build that before I look up how to actually solve it. If you’re interested enough to try it, build a JSON parser, which is something I like to do.
  • nesarkvechnep 1307 days ago
    What is your prior knowledge? I ask because it's interesting you think learning a language is usually easy. Knowing the syntax is not knowing the language.
    • fuadnafiz98 1307 days ago
      I am 3rd year CS grad. As you can expect, I have basic knowledge of C/C++, java, javascript, php, python. Like javascipt is hard, like concepts of closure, callback or even functional programming concepts like monoids, map, reduce. But the starting is easy. I don't think that learning programming is easy, but Rust needs more indepth knowledge I guess which I don't have.
      • nesarkvechnep 1307 days ago
        You'll have it. Just give it time and think deeply about the hard topics. Knowledge of functional concepts help a lot.
        • fuadnafiz98 1307 days ago
          agreed...I'm also learning fp in js
          • nesarkvechnep 1303 days ago
            Not the best choice in my opinion as there's no concept of immutability in JS.
  • aronpye 1307 days ago
    Have any C developers jumped ship to Rust?

    I can see C++ developers migrating as the philosophy of C++ seems to be more aligned with Rust than C (C solves problems by forcing you to write more C, C++ solves problems by adding more language features).

    I’m not sure whether I would enjoy using Rust as I dislike the verbosity of C++ with its more complicated syntax and multitude of “features”.

    • saurik 1307 days ago
      I have seen--and agree with--the opposite argument: that C++ already has a lot of similar patterns and solves enough of C's safety issues that the remaining limitations become a tradeoff against the things where Rust is still far behind C++ (such as in value templates, to name just one of a million things), that the move for C developers feels a lot more motivated than for C++ developers (and the Rust people seem to de facto agree, whether they say it explicitly or not... when I have pressed them on things that make Rust really unappealing to me the defense ends up as "we were courting embedded systems developers", which is the only set of people I imagine still really feeling a need to code in C... though I frankly also can't imagine the ones I know of moving to Rust).
    • steveklabnik 1307 days ago
  • rrao84 1308 days ago
    Follow-up question .... why learn Rust?

    (asking to understand and not troll)

    • fuadnafiz98 1307 days ago
      I never really worked in any system language or strict typed language before, I wanted to learn multi threading or parallel processing, so I thought to learn those concepts with Rust. I am into web development and also quite interested in web assembly, so overall I want to give this a try. :|
  • A-Train 1307 days ago
    I like this one https://github.com/rust-lang/rustlings. It is a set of exercises in which you must fix fragments of the code to pass the test.
    • firloop 1307 days ago
      Strongly second Rustlings. I found it to be quite fun — felt like playing a puzzle game... the pacing of the course is very well done.

      Once you get the fundamentals of Rust down, I recommend writing something multi-threaded. It's not that much harder than writing single threaded Rust and a good test of knowledge; in my case I wrote a tiny web app:

      https://github.com/ylukem/pin-go

  • mraza007 1307 days ago
    What do you think about learning C++ over Rust Because if we look at C++ it has a very mature ecosystem as it has been around for a long time and alot of companies are using C++
    • lionkor 1307 days ago
      I second this as a possible alternative. I feel like both are good to learn. Since starting with C++ I feel like i have become a much better programmer, more so than when I was using python, java or C#. It forces you to solve problems that are always there, but are usually abstracted away.

      Learning Rust afterwards is good, too, because you might understand how to write good, safe code already, making the safeties Rust provides more useful.

  • potatochup 1307 days ago
    Aside from the rust book, I learnt by porting some older python scripts (~100 lines) into rust. It was good starting with something that had a simple data flow so you don't have to worry about lifetimes as much, and performance isn't a concern so you can just ".clone()" if you don't want deal with references
  • trevorBelmont 1307 days ago
    Change gender
  • trevorBelmont 1307 days ago
    Change gender and become a tranny. Dilate everyday.