Hacker News new | ask | show | jobs
How to Learn Modern Rust (github.com)
146 points by zathan 1375 days ago
18 comments

This looks like a great resource, starred and upvoted.

I'm planning to learn Rust next, going to start in a week after a job interview I had already lined up at Google.

I worked with many languages professionally (JavaScript, TypeScript, Java, Python, Go, and now Dart) and many others at the university (C, C++, C#)...

...and Rust is very appealing to me. It's a modern language where the dev tools are straightforward, no need to deal with learning 30 years of legacy conventions, great performance that's on pair with C/C++, yet, at the same time high level and easy to read and reason about. The language is still young enough to make a dent in the ecosystem and build stuff for fun without people whining about JavaScript fatigue. It's versatile, so it can be used (at least theoretically) for web backend, frontend, desktop apps, command line tools, systems programming. It has all the good parts from OOP and FP.

Yes, I'm at least partially responsible for having "xyz rewritten in Rust" almost every day in the top list on HN.

One thing in a bit worried about is the job market, I've been paying attention to job adverts for months and I didn't see many companies that I'd like to join that use Rust in my area (Germany).

Learning it and doubling down on Rust feel like a gamble, but at the same time, I can't imagine that Rust will not be one of the most important languages of the next decade.

Most Rust jobs are in the blockchain space, which is unfortunate for those uninterested in blockchain technologies.
My impression is a bit different. I know a bit of Rust, and used to know C++98 inside out, but moved to more functional languages 15 years ago.

I recently added a Rust keyword to my LinkedIn profile and Who's Hiring threads, just to test the waters. Many EU companies of all sizes got in touch with really interesting proposals.

It's a systems programming language, so there are lots of problem domains it can cover.

We at Intervall are looking for excellent (Rust) developers:

https://intervall.io/en/jobs.html#rust-developer

> Degree in Computer Science, Mathematics, Natural Sciences, Electrical Engineering or comparable qualification

welp.

> I can't imagine that Rust will not be one of the most important languages of the next decade.

As someone new to this industry, I'd love to hear a counter argument to this if anyone has one.

Rust is mostly a systems programming language - like C++. The amount of jobs that require application development in such languages is a lot smaller than e.g. the amount of jobs for generic frontend (Javascript/Typescript) or backend development, since most businesses don't need to build an operating system, database or embedded system. That's why the job market for C++ was even small before Rust even showed up.

Of course one can also use Rust for applications which previously used Java, and still benefit from a stricter type system and a potential efficiency improvement. But the selling proposition becomes a bit tougher. Con's for adopting Rust are the higher complexity, and a potentially reduced developer ecosystem for particular domains which have a ton of Java/C#/Go/Javascript libraries.

People do seem to use it to eliminate random GC spikes, which can matter on the web too.
It’s a complicated language, just like C++. A lot of that seems like accidental complexity from wanting to encode various attributes of algorithms and data in the type system. If one wants to use a straightforward low-level language, Rust is not it. Judging by its evolution, it will never be that either.

I can’t say I’ve ever known Rust very well, but I knew the basics and decided to wait and see before investing more time until there’s a clear sign that the language is becoming popular outside blockchain.

I don’t regret learning Rust, but haven’t seen any benefits either given my many years of C++ experience.

This is a good list, although it contains a lot of redundancy - at least, the first "how to learn" links - the youtube videos cover the same material over and over again. They are good - you may not need to watch every one in order as the author suggested.

My approach has been considerably, uhh.. lazier, if you will:

I just read through the rust book available on http://rust-lang.org. It is easy to follow although, sometimes it doesn't fully explain the "why" behind certain things to idiots like me. For that, I turned to a quick online search, which brought up helpful blog posts, Reddit and Stack Overflow posts.

Thats it. Next, I'll try to wrap my head around Actix to create a web server.

Is Rust old enough for there to be a 'modern' Rust?
Yeah, not really. The only big changes to the language core were non lexical lifetimes, match ergonomics, lifetime elision, auto-deref, and async, although all of these are already so old now that I wouldn't consider them constituents of modern Rust; they're just (unqualified) Rust at this point.

Releases tend to bring some minor improvements like functions you wished had always existed or making non-const functions const, but that's pretty much it. Rust is a remarkably stable language.

Code that predates the 2018 edition can have some cruft, especially with respect to the module system.
These are relatively minor things, and most of them can be cleaned up with `cargo fix` and `cargo clippy --fix`.
You can't run `cargo fix` on blog posts from 2017
I think so? Modern c++ (c++11) came 13 years after c++98. Rust has been released for close to or longer than that depending on your definition of released.
Note that while C++98, the first standard came out in 1998, the first public release of C++ was in 1985, so it's more like 26 years
Yeah, I remember looking at C++ sometime in the 80s. If memory does not evade me I think it was preprocessor back then.
Rust has improved in a number of significant ways since 1.0, those improvements are things that make it easier to work with in a number of ways. One way to think about this topic is if you found the language too hard in the beginning you may find it easier to work with now.

Also, since it was released a lot of patterns have evolved to work around the restrictions the language puts in place, and those are good to learn.

sort of? when i first learned it there was no async/await, no `?` operator for simplifying error handling, and lifetime elision was a whole other story, and you seemed to need lifetimes for any reference (can't remember but it's much better now). But is that really enough change for a new kind of rust (instead of just say, learning async rust vs normal rust?). not sure.
Isn't this what "editions" are supposed to handle, in part?
Editions are only necessary for otherwise-backwards-incompatible changes, to avoid breaking existing code. Even relatively major language features like the ? operator were shipped without an edition bump. But for example I think the await keyword itself was added as part of an edition, because it was incompatible with existing code that had a method named await.

The messaging around the 2018 edition was a little different here, with some attempts to use the edition release as an opportunity to advertise and summarize all the features that had shipped since 2015. But I think folks decided that was confusing, and with the 2021 edition the messaging was toned down.

Yes, that's a fair point about the actual purpose of editions being to handle forwards-compatibility.

Informally though, I think there are certainly a subset of people that use "Rust 2021" to mean all of the features included up to that point, even if it's not the precise definition.

Arguably it's young enough that all Rust is 'modern' Rust.
Code from before match ergonomics and NLLs definitely feels pre-modern.
If this was JavaScript, the current modern would be old school by the time I finish writing this sentence.
No, that sort of talk isn’t helpful.
My first piece of advice is to just start writing code.

If you are not specifically interested in super high performance systems level code, my second piece of advice would be to write code that avoids lifetime annotations until you get the basics of the borrow checker down.

For me, this meant writing a gRPC API with Rust using `tonic` with a `diesel` based persistence backend and observability with `tracing` and `opentelemetry`. This gives you a good survey of the basics and you'll learn about all of the core traits and language features in the process.

Just start coding while avoiding lifetimes is great advice, but that's easier said than done. Rust makes some hard things simple and exposes hidden complexity in things you thought were simple.

Maybe I'd reframe it as "just start writing code, and use RC<> liberally to avoid lifetimes until you get a handle on them."

Also avoid async for that first project too.

Yes - that's also good advice (using Arc/RC to liberally avoid ownership issues). I've personally had good experiences with async, but I can also see how that could be challenging depending on the background you are coming from.
This is what I did. Still haven't figured out lifetimes or async, but I was impressed with how easily I managed to write something that works[1]...

[1] https://github.com/jcuenod/clickhouse-set-cover

Slightly off topic question/comment: You are running an async server, together with a blocking database client? That sounds more like a very tricky place ot get started. Are you dispatching all your database queries into an extra threadpool?
Yes, as you have expected tokio has spawn_blocking which allows you to throw misbehaving code into a thread pool.

This started to disgust me so I jumped to sqlx.

Yes - what throwaway said. Good suggestion as well to use sqlx instead.
This list undoubtedly took a lot of effort to compile, but I fear it might intimidate a newbie.

I’d say the guide to learn modern rust could be much simpler - read The Book, write some code, and listen to Clippy (the linter) and apply rustfmt regularly.

Almost all Rust code out there looks similar to each other because they pretty much follow this process - follow the standard linter and code formatter. The best part is, each Rust release introduces few changes so it’s easy to stay in tune with best practices.

Four : Rust is what, less than a decade old? Rust itself is modern, there's no 'old' or 'ancient' rust, it's all modern, no?
There is Rusty Rust and Shiny Rust...
I love Rust and this is a great resource that I will certainly refer too, but I wonder if there is a little too much Rust language anxiety since we have a so many articles on "how to X in Rust". Doesn't that point to some complication if the thing being implemented is necessarily so tightly coupled with the language its implemented in (ie in a Write TCP in Rust type resource) that you need a special resource on how to to do it? There are some exceptions where like trying to do Linked Lists in Rust where the language will do everything it can to stop you, merits its own article.
A lot of the links look reasonable.

The substring section[1] looks a bit weird though. If you're learning Rust, diving right into how to work with char indices instead of byte offsets does not feel like the right thing to cover right away. You might really need that, but chances are you don't and would be much better served by a section that talks about how you probably don't want char offsets at all. But even that doesn't seem like you should whack a beginner with right away unless they have a specific hang-up on it.

Beginner string stuff should be talking about string representation and going over the &str and String APIs. And depending on how early you get to it in the overall tutorial, probably using it as a springboard to talk about lifetimes.

But writing code so you can go out of your way to do something that is probably wrong in the first place? Noooooo.

Anyway, sorry to pick at this specific point, but the Gell-Mann amnesia effect comes to mind.[2]

[1]: https://github.com/joaocarvalhoopen/How_to_learn_modern_Rust...

[2]: https://en.wikipedia.org/wiki/Michael_Crichton#GellMannAmnes...

I'd be really interested in a series that would go over how you might write code in one language (say c++, java, python, whatever), how you might try to write it in Rust and the problems it entails, and then how to write it properly.

I haven't written Rust in 3-4 years, and trying to get back into it is painful.

I've been meaning to dig my teeth into rust for a long time. JT's intro to Rust videos[1] are first on my list for when I can devote the uninterrupted hours.

[1] https://youtu.be/gesNaLkUJeA

If, on the other hand, you’re interested in pre-modern Rust, there’s always this repo: https://github.com/graydon/rust-prehistory
Some people need to get with the picture and drop those antiquated 2021 practices. Puke!
It's a decent joke, but one of the reasons I only took up Go almost a decade after it got started was that I wanted to invest on a stable language ecosystem that wasn't after the fad of the week (like certain runtimes we all know).

I'm actually looking forward to Rust having a few more years under its belt so I can do more than experimentation with it (and yes, I've seen the Oxide stuff, and there is plenty we can call stable right now -- I just want it to be a bit more weathered...).

Go: started 2007, announced 2009, 1.0 2012

Rust: started 2006, announced 2010, 1.0 2015

The weathering on the two languages seems fairly similar.

In fact it could be argued that Rust is more stable. Golang is talking about a breaking Go2, Rust has a fairly good forward compatibility story and plans.

I don’t think there’s any plan for a Go 2. I’m willing to bet we won’t see one in the next 10 years. The main feature that might have required breaking changes (generics) was introduced successfully without any breaking changes.

Rust has no plans for 2.0 either.

Both are stable languages that have been making steady progress.

The first link states that Go 2 is TBD and in the event there is a Go 2, interop must be easy.

The second link has Rob Pike state that there probably won’t ever be a Go 2.

A lot of the frustrating parts seem to be related to async/await, and that seems lightly covered here.

In particular, the intricate dependencies needed to do basic stuff, and choosing among many approaches.

Why would this be better than the Rust Book?

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

Can I get a job with Rust?
They're out there! I found a gig at a startup not in the blockchain space working with Rust, but felt pretty lucky to find it. Most of the jobs are in crypto nonsense.
Why are there only those jobs?
Many software companies started in the last 3-4 years revolves around the blockchain. These were free to choose the best language suited to their use case. Many chose Rust, first released 7 years ago and started gaining momentum 3-4 years ago. It had good performance, fewer foot guns, good type system so it made sense for them.

Companies that started before Rust gained critical mass might already have significant investments in one language and don’t want to rewrite. This is the majority of companies. Let’s say GitHub won’t rewrite their main Ruby application, but if they were writing a new code search backend, they might choose to write that in Rust. The majority of GitHub devs would continue to write Ruby.

That means older companies (started before blockchain was hot) are going to skew towards older languages while newer companies are more likely to adopt newer tech.

Is this a normal amount of studying to be considered an expert in a language? Like not a world authority, but an expert as far as professional software development hiring.
what word are people going to use after modern. it's kind of like using the word new. we don't use modern rust around here anymore, just modern new new modern rust.
In other contexts they use word 'post-modern' and after 'post-modern' there is 'contemporary'.
A lot of people are getting really hung up on this. "Modern Rust" is just current Rust. Once Rust moves on, that will be modern Rust and what we once called modern will no longer be modern. Like all things. You might as well get upset that somebody said something will happen "tomorrow" because in 24 hours it won't be "tomorrow" anymore.
i didn’t mean rust. i meant any of these modern technology articles
So Rust is now old enough for people to talk about "Modern" Rust?

I'm either missing something or words don't mean what they used to...

It's more than a decade old, and I have learned Rust on 3 occasions - first when I worked at Mozilla and heard about Rust as a project Graydon was working on at either a lunch and learn, or just chit chat around the Mozilla Vancouver office. Later I learned how to write some tools in Rust after not touching it in a few years when I changed companies. Finally, a year and half ago I had to actually start working in Rust on the regular as a dev and security engineer at Fastly.

There were substantial changes in work flow and tooling each time I dove in and learned the correct way to do things.

How’s your experience been working with Rust regularly in a professional environment?
I enjoyed it, but I changed jobs and companies a few months ago, and now I do spreadsheets and hold status meetings for a living :P

Still using it for personal projects.

I thought entrust was modern, now there is a modern rust too!? :P