Live data from Hacker News

Exercises to Learn Rust

rust-exercises.com

91–100 of 129 posts

Re: Exercises to Learn Rust

#91

What do you folks normally do after learning a language like this? (Assuming you don't use it for your day job.)

If it's coming towards the end of the year, solve Advent of Code in the new language you learned. AoC scales gently. On day 1 if you can't see how to do it that's going to be because you didn't really understand your new language. By day 25 it's very likely that you can't figure out how to solve the problem yet in any language, if you're up for it, maybe solve it in your existing favourite and then try the new one.

Because lots of people do AoC, especially in popular languages like Rust or C++, you can see other people's solutions in the AoC Reddit solutions thread each day, which are often inspiring -- you learn new idioms, library features, or even whole CS concepts.

Re: Exercises to Learn Rust

#92

This looks like a great resource! https://rust-exercises.com/03_ticket_v1/07_setters This shows why I wouldn't use Rust for anything. Seems like a lot of verbosity for gains that don't really apply whatsoever for the kind of work I do (web apps and APIs). You have to remember let/mut fine, but then ownership/borrowing, and finally this `into()` thing - yuck! Like washing your face with sandpaper.

Well, nobody forces you to use the setters/getters pattern. For internal implementation, you could access everything directly. For example, Zig encourages this style of programming.

In my experience in Rust, the use of getters and setters is less common compared to some other languages like Java.

Re: Exercises to Learn Rust

#93
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…

> 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.

I found that when learning Rust, it approximated the mental model that I had already developed for programming. Move semantics and such just felt right. I had used around 10–15 other programming languages by then, but none were even remotely Rust-like.

I don't know why this is. It can't be that Rust is the objectively or even subjectively right way to think about programming. It has to be that its concepts were simply already intuitive to me, but I wonder why that is, when so many people struggle.

Perhaps it's because of neurodivergence, maybe the language just matches the way I think in general and that's why it made sense so quickly. I'd probably make a terrible teacher, because I just do not understand the struggles people have with Rust, and I can't just teach someone to think the same way I do.

Maybe when existing Rust users try to write material for new developers, they write in a way that, for lack of a better way of wording it, is only really accessible to their own neurotype. In other words, it doesn't really help the people that genuinely struggle with Rust's way of thinking, it primarily helps people who already have this way of thinking.

Re: Exercises to Learn Rust

#94
I skimmed through a few sections in which my rust knowledge is basic at best (threads). Really enjoy the no-nonsense, not-a-word-wasted style.

My first thought after spending 30 minutes with this that it could easily become my new no. 1 recommendation for rust onboarding, toppling the zero2prod book.

Then I figured out why this felt familiar, it's from the same author :D

Will definitely dive into it this weekend.

Re: Exercises to Learn Rust

#95
post #22

Earlier quoted context omitted.

There’s a world outside of web development.

Also, just because these examples are verbose doesn't mean that all Rust code is this way. Accessors/mutators aren't used super often in my experience, and the builder pattern is used occasionally, but isn't pervasive. (I have historically been very skeptical of Rust on the web, but by now, I find it pretty pleasant. I of course know Rust very well already though.)

Agreed. There's also another aspect at play: to build knowledge one step at a time with this learn-by-doing approach, you have to get learners to write code that's not perfectly idiomatic along the way. You then correct and refine those first drafts as you progress along.

In the case of setters, we get rid of them at the end of that chapter by using the newtype pattern thus guaranteeing that field invariants can't be broken even if you can access them directly.

Re: Exercises to Learn Rust

#96

I skimmed through a few sections in which my rust knowledge is basic at best (threads). Really enjoy the no-nonsense, not-a-word-wasted style. My first thought after spending 30 minutes with this that it could easily become my new no. 1 recommendation for rust onboarding, toppling the zero2prod book. Then I figured out why this felt familiar, it's from the same author :D Will definitely dive into it this weekend.

Zero2prod doesn't really teach Rust, it's more about setting up an API for people who already know Rust.

Re: Exercises to Learn Rust

#97

Earlier quoted context omitted.

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…

> 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. I found that when learning Rust, it approximated the mental model that…

Certainly in regards to say, ownership, Rust has to be very explicit about things which you'll find in the literature make sense for other languages but maybe are barely mentioned when they're taught.

For example the life of objects is something Bjarne Stroustrup's early editions of his C++ book neglect, basically saying yeah objects come into existence and then they're later destroyed and it's only in the third edition once C++ has more powerful techniques for this stuff that suddenly it's important that C++ programmers care about this and there's IIRC a whole chapter of the book.

It is also said that although Rust looks like a semicolon language, like C or Java or something, it's actually not like those semicolon language at all, it's an ML, the syntax makes it more palatable for semicolon programmers to learn and looks more "serious" for a systems language.

As an ML, Rust gets a solid foundation in its type system. Rust has a type with no values, and a type with one value, Sum types and Product types, so we're on firm ground here, we can do type arithmetic. Languages like C++ struggle to have a type with one value†, and can't really do "no values" at all. It's like your system of arithmetic doesn't have zero. You can limp along, the Romans did, but it's an unenviable situation.

† The C++ language isn't really sure how to handle these types properly because its rules say they need at least one byte of storage - but that entire byte is just padding. It's not insurmountable but it's very silly.

Anyway, I think what you're feeling is more real than you've allowed for. This is concretely a better foundation, that's not an illusion. It's not perfect but the sense that this is how things should be makes sense compared to other popular languages.

Re: Exercises to Learn Rust

#98
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).

That doesn't match with my experience: I learned the language from scratch just fine with Rustlings. (In fact, I found it more approachable than the Rust Book.) The first few groups of exercises in it walk you through the basic syntax and semantics, to the point that I found it almost tedious to work through, but I ultimately came to appreciate it.

In the most recent Rust Copenhagen Hack Night, half a dozen people took their first steps with Rustlings.

It was my experience that it worked really well.

Some people were speed-running it, others took their time to read the book references that came up once in a while.

These 100 exercises build on the same interactive project format as Rustlings, so I would assume they're both great.

Re: Exercises to Learn Rust

#99
post #96

I skimmed through a few sections in which my rust knowledge is basic at best (threads). Really enjoy the no-nonsense, not-a-word-wasted style. My first thought after spending 30 minutes with this that it could easily become my new no. 1 recommendation for rust onboarding, toppling the zero2prod book. Then I figured out why this felt familiar, it's from the same author :D Will definitely dive into it this weekend.

Zero2prod doesn't really teach Rust, it's more about setting up an API for people who already know Rust.

And it also isn't 100% best-practise, more like all-practise. It tries to show any and every way you could approach a problem while somehow keeping it minimal. Really like it but if you follow the tutorial 1:1 you'll most likely get frustrated

Re: Exercises to Learn Rust

#100
post #50
post #37

Earlier quoted context omitted.

You get ridiculous performance gains with Rust a web backend. Even Microsoft is rewriting part of their C# backend to Rust on the 365 application side of things. Which is where you get to deal with the hefty ms-graph api which handles literal fucktons of data. Anyway. It is more verbose than something like Go or Python. I’m not sure it’s really so bad compared to most languages, but some of the benefits you get from…

Office team never was a big .NET fan, and they were partially responsible for Longhorn's failure, see also Hilo C++ tutorial made by the team as part of Vista SDK tutorials, or their love for Webwidgets to C++ code, so that isn't that surprising. It isn't as if C# vlatest wouldn't be able to take up the task, Bing, XBox game servers, and other large scale services are fully on .NET.

But like the Office services, these are all significantly older than Rust. Bing the branding is like 15 years old, the underlying service is older still (as "Live Search")

So when this stuff was built the high performance option was C++ and there is an obvious reason to avoid that if you can. Rust means you can have the excellent performance without the absurd foot guns. Whether you chase that depends on other strategic priorities.

Post reply on HN