Live data from Hacker News

How I went about learning Rust

eli.thegreenplace.net

241–250 of 303 posts

Re: How I went about learning Rust

#241
post #233

One great thing about the Rust books and tutorial -- you can easily enjoy them offline, right out-of-the-box. I learned the basics of Rust on a long plane ride with no WiFi. What a great way to pass the time!

I don't see anything explicitly calling out what to download in nonethewiser's link. How did you end up grabbing these things for offline learning?

Re: How I went about learning Rust

#242

“How” is the stupidest word to auto-censor. Removing it completely changes the meaning of titles. It makes articles seem vapid or banal when they wouldn’t otherwise, and vice versa.

It changes the meaning of some titles. It makes more of them less baity.

The danger with these arguments is that you only notice the cases that don't work. That's a 100% failure rate! Can't get more stupid than that!

pg suggested this edit to me years ago and I spent a long time back testing it on old titles. At the time, it was a clear win. I suppose it's possible that title conventions have changed since then and taking another look might be a good idea.

Re: How I went about learning Rust

#243

Serious question: can I just use smart pointer like feature of Rc/Arc combing with Mutex or RWLock instead of fighting borrow checker? I know this practice is shunned upon by Rust purists but I like to see how practical it is in real life and project. Especially around using Rust as a safer but more performant language instead of pushing for ultimate zero-cost abstraction and top notch performance.

Although I can't recall them off the top of my head, several guests on the Rustacean Station podcast have suggested exactly that when one is getting their feet wet with Rust (put .clone() everywhere, put Arc> everywhere, ..etc).

The idea is that once you are familiar with other aspects of the language (syntax, sum types, traits, modules), you can go back and try to master the borrow checker.

Re: How I went about learning Rust

#244
post #233

One great thing about the Rust books and tutorial -- you can easily enjoy them offline, right out-of-the-box. I learned the basics of Rust on a long plane ride with no WiFi. What a great way to pass the time!

I don't see anything explicitly calling out what to download in nonethewiser's link. How did you end up grabbing these things for offline learning?

There’s a “READ THE BOOk!” link to https://doc.rust-lang.org/book/. That page says:

“The HTML format is available online at https://doc.rust-lang.org/stable/book/ and offline with installations of Rust made with rustup; run rustup docs --book to open“

More importantly, it has a “next page” arrow at the bottom right, and a TOC pop-up at the top left of the page.

Re: How I went about learning Rust

#245
post #233

One great thing about the Rust books and tutorial -- you can easily enjoy them offline, right out-of-the-box. I learned the basics of Rust on a long plane ride with no WiFi. What a great way to pass the time!

I don't see anything explicitly calling out what to download in nonethewiser's link. How did you end up grabbing these things for offline learning?

It's automatically available if you installed with rustup! Try this:

rustup docs --book

Re: How I went about learning Rust

#246
post #233

One great thing about the Rust books and tutorial -- you can easily enjoy them offline, right out-of-the-box. I learned the basics of Rust on a long plane ride with no WiFi. What a great way to pass the time!

I don't see anything explicitly calling out what to download in nonethewiser's link. How did you end up grabbing these things for offline learning?

I use devdocs.io, but I think you can simply download the book using cargo/rustup ...

Re: How I went about learning Rust

#247
post #200

Earlier quoted context omitted.

The compiler would enforce Number-ness every time I try and run a function that takes a number, right? Wouldn’t I still have to check for NoScore? > a sum type with units of Score(Int) and NoScore won't allow assignments of any other "null" instances. I get this part - I wouldn’t be able to assign ‘NewBornBaby’ (my name null) to ‘NoScore’ (my score null)

>Wouldn’t I still have to check for NoScore? That's right, and the compiler will reject programs where you don't do this. It's a set of safety rails for your code. You pay a dev-/compile-time cost in exchange for your programs not exploding at runtime.

Yes but that’s no less work than checking for null in TypeScript. The parent said:

> In your example, you still have to manually check if there's a value every time, but this is not compiler-enforced.

Re: How I went about learning Rust

#248
post #200

Earlier quoted context omitted.

The compiler would enforce Number-ness every time I try and run a function that takes a number, right? Wouldn’t I still have to check for NoScore? > a sum type with units of Score(Int) and NoScore won't allow assignments of any other "null" instances. I get this part - I wouldn’t be able to assign ‘NewBornBaby’ (my name null) to ‘NoScore’ (my score null)

> The compiler would enforce Number-ness every time I try and run a function that takes a number, right? > Wouldn’t I still have to check for NoScore? No, because you differentiate between the sum type (e.g. Maybe in Haskell) and the number type at compile time. It's a small distinction - there will still be one or two places where you ask "is this a Maybe-score, or a Just-Score, or a No-Score", but the upside is tha…

> I.e. if you pass maybe-scores to something that computes the mean, you'll get a compiler error. The writer of the mean function doesn't need to care you've overloaded an error value onto your numbers.

If I pass a null into something that calculates an average, taking numbers, the TS compiler will complain now. The writer of mean() (assuming mean() is typed) doesn’t have to know anything about my code.

Re: How I went about learning Rust

#249
post #233

One great thing about the Rust books and tutorial -- you can easily enjoy them offline, right out-of-the-box. I learned the basics of Rust on a long plane ride with no WiFi. What a great way to pass the time!

This sounded interesting but I was confused by what you meant by "the book." Looks like that's how it's commonly referred to https://www.rust-lang.org/learn

This is the "The Rust Book": https://doc.rust-lang.org/book/ Affectionally known as "the book"

Re: How I went about learning Rust

#250
post #100
post #14

Earlier quoted context omitted.

Rust is the more elegant and powerful language. Creating a new language and repeating the "billion dollar mistake" by including null (sailing under the brand name "nil" in Go) is just crazy. Error handling is another strange thing in Go. And generics have been only introduced recently, but there is hardly any support for libraries in it (now). While Go is definitely fast enough for most scenarios, it is not the best…

> Creating a new language and repeating the "billion dollar mistake" by including null (sailing under the brand name "nil" in Go) is just crazy. Can you explain? What do I set ‘score’ to when someone hasn’t sat the test yet?

Rust has Option which you opt-into for cases like the one you describe.

What's special is that it's not like Go/Java/JS/etc where *every* pointer/reference can be null, so you have to constantly be on guard for it.

If I give you a Thing in Rust, you know it's a Thing and can use it as a Thing. If I give you an Option then you know that it's either a Some or None.

If I give you a Thing in Go/Java/etc well, it could b nil. Java has Optionals...but even the Optional could be null...though it's a really really bad practice if it ever is...but it's technically *allowed* by the language. Rust doesn't allow such things and enforces it at the language and compiler level.

Post reply on HN