Live data from Hacker News

Exercises to Learn Rust

rust-exercises.com

81–90 of 129 posts

Re: Exercises to Learn Rust

#81
Obligatory reference to the Rosetta Code site which shows a good number of popular and less known problems with solutions in many programming languages.

https://rosettacode.org/wiki/Rosetta_Code

Edit: it seems the "more..." label down the 1st list to see all examples is broken. To explore the full list use this link instead:

https://rosettacode.org/wiki/Category:Solutions_by_Programmi...

Re: Exercises to Learn Rust

#82
post #51

Surprised no one has mentioned another great and similar resource called Rustlings [0] (yes very punny name). You are given some files with todo statements which you'll need to fix and make the code compile and pass all the tests. It's an interactive way to learn which is what got me through learning Rust a few years ago. [0] https://github.com/rust-lang/rustlings

The difference is that Rustlings requires the person to already know Rust whereas the link on this post (100 Exercises to Learn Rust) starts teaching Rust from the basics (assuming that the person knows another language).

To me "the basics" means either no programming at all, or something rudimentary and half-remembered like you did simple Logo turtle graphic programming in math class as a ten year old and now you're thirty. Not "knows another language".

I think it might be interesting to develop Rust-as-first-language teaching materials, but that's not what this is. Move assignment as your primary assignment semantic, borrowing as your metaphor rather than introducing the confusing idea of "addresses" (in Rust many things we can borrow don't have a meaningful address, but it's fine) and so on.

Re: Exercises to Learn Rust

#83
post #22

Earlier quoted context omitted.

There’s a world outside of web development.

He's right, though. Languages today shouldn't force you to jump through low-level hoops if you just want to write high-level logic. Likewise, the low-level devices should be easily and ergonomically accessible. Rust is phenomenal at the latter but weak at the former.

But who's forcing you? Oh .. the companies jumping on the latest "in Rust" hype. I see.

Just do your thing and be good at it.

PS: There was this VSCode extension to do BI stuff in the IDE (quarylabs/quary) showed here on HN and once I saw the CLI core having "Rust-based" as a feature I just closed the tab. What does "Rust-based" even mean? The tool may have been good but Rust is not a feature.

Re: Exercises to Learn Rust

#84
post #51

Earlier quoted context omitted.

The difference is that Rustlings requires the person to already know Rust whereas the link on this post (100 Exercises to Learn Rust) starts teaching Rust from the basics (assuming that the person knows another language).

To me "the basics" means either no programming at all, or something rudimentary and half-remembered like you did simple Logo turtle graphic programming in math class as a ten year old and now you're thirty. Not "knows another language". I think it might be interesting to develop Rust-as-first-language teaching materials, but that's not what this is. Move assignment as your primary assignment semantic, borrowing as yo…

[deleted]

Re: Exercises to Learn Rust

#85

Wonder if there's anyone who (1) is reasonably comfortable in some popular programming language(s) and (2) has gone through these exercises could/would share their take on how helpful/useful these are? Context: I've been doing Java professionally for 10+ years, Python, JS a few years ago, C++ way earlier in my career (early 2000s).

I can’t get up to speed with rust using these kinds of material.

Haven’t looked deeply at this one in particular but they tend to teach you patterns and approaches. That works for a lot of languages. Got into zig pretty fast for example. You can start writing go in 2 days and even if you write shit code at first, it will run.

But I can’t get productive in rust and that kills my enthusiasm.

Re: Exercises to Learn Rust

#86
post #41
post #21

Earlier quoted context omitted.

I got a Hamlet vibe from it when I picked the book up when it originally released. It could just be because it looks pretty sick though

Alas, poor Yorick; I knew him well, Ferris. (Slightly more seriously, the project to replace the borrow checker was called Polonius[1], so it wouldn't be the first Hamlet reference in Rust land.) [1] https://github.com/rust-lang/polonius

To follow up that movie reference with the response in a different movie where that line is misquoted, “Where’d you hear that, a renaissance festival?”

I haven’t seen that movie a lot, but that scene (and really the entire movie) has been seared into my consciousness for 30 years. It was just the exact thing I wanted at that point in my life.

Re: Exercises to Learn Rust

#87
post #51

Earlier quoted context omitted.

The difference is that Rustlings requires the person to already know Rust whereas the link on this post (100 Exercises to Learn Rust) starts teaching Rust from the basics (assuming that the person knows another language).

I think Rust is close enough in syntax to C and Java so that just about any adept programmer can figure it out.

Close in syntax maybe, but you need quite a different mental model to build complex programs.

Re: Exercises to Learn Rust

#88
post #79

Do you know similar sources for C?

https://exercism.io/tracks/c

Exercism.io is not just limited to one language it has a track for most popular languages. I've used it a couple of times and can definitely recommend it. You get to compare your solution with other (top-rated) solutions and you also get mentorship at times (depending on availability I guess).

Re: Exercises to Learn Rust

#89
post #12

I maintain a list of Rust tips and tricks for people who are looking to dig a bit deeper: https://geeklaunch.io/blog/rust-pro-tips-collection/

Cool list! I learned a lot of new things, kudos. One suggestion: where you talk about using AsRef , might be worth suggesting IntoIter, where it makes sense? IIRC that's what std uses for functions that aim at being generic over data structures and iterators (I might be remembering wrong, though). In any case let's not digress from the truth: amazing list.

There are a few of these conversion traits (for turning some kind of Thing into a Thing with a different purpose)

You're thinking of IntoIterator, which is a trait for when you want an Iterator, maybe what you've got is already an iterator, but maybe it isn't yet and yet it could easily be transformed into one (like say an array), so in either case IntoIterator::into_iter() gets you an iterator instead of whatever you have now -- the thing you had before is consumed by this.

Another you may find uses for is ToString, which says this obviously could be a string and I want the string. Unlike IntoIterator this does not consume the thing you wanted a string for.

There are also a suite of generic traits for converting to another type, From, Into, TryFrom and TryInto. As the person consuming things, prefer TryInto if you're clear what should happen when you can't, or Into if you need it to always work. As the person who is implementing the traits, prefer to implement From or if you can't TryFrom. Rust automatically cascades the conversions in one direction, so if I implemented From for Bird, and then you later write code which needs TryInto, that'll work just fine with a Goose using the code I wrote, because Rust concludes how to use my conversion to make it work, automatically - Rust will even be able to see that your "What if I can't?" error handling code will never run, and optimise it out of production code since I provided From so this cannot fail - its Error type is Infallible, an Empty type.

Re: Exercises to Learn Rust

#90

Wonder if there's anyone who (1) is reasonably comfortable in some popular programming language(s) and (2) has gone through these exercises could/would share their take on how helpful/useful these are? Context: I've been doing Java professionally for 10+ years, Python, JS a few years ago, C++ way earlier in my career (early 2000s).

This type of exercise doesn't quite help me. When I was learning Go, I couldn't find one that suited me, so I wrote one as I learned: https://github.com/hliyan/learn-golang/blob/master/day-01/he...

For learning JS internals, I used this: https://johnresig.com/apps/learn/

Post reply on HN