This is, more or less, how I learned Rust circa 2015 (might have been a couple years later). I quickly started to write programs like I would have in C but got completely thwarted by the borrow checker because I wanted pointers everywhere. This made me throw my hands up and leave for other languages. However, 8 years later I did eventually come to love rust after learning the One Weird Trick of using indices instead…
> got completely thwarted by the borrow checker IMvHO, Rust Ownership and Lifetime rules aren't really that hard to learn. The only trick is that a programmer cannot learn Rust exclusively by trial-and-error (which programmers love to do), trying dozens of syntax combinations to see what works. A programmer is forced to learn Rust by RTFM (which programmers hate to do), in order to understand how Rust works. That's a…
A half-hour to learn Rust (2020)
51–60 of 86 posts
Re: A half-hour to learn Rust (2020)
#52Earlier quoted context omitted.
Not sure if I disagree but your example is terrible. Let patterns in if statements greatly simplify things. The alternatives are a lot more convoluted. See example from code I wrote this week: https://github.com/trane-project/trane/blob/master/src/data/... Without the let, I'd have to do a match statement followed by an unwrap just to check if a field in an enum is set.
> Without the let, I'd have to do a match statement followed by an unwrap just to check if a field in an enum is set. You... would not? An `if let` trivially desugars to a `match`. if let = { ... } becomes match { => { ... } _ => {} }
Re: A half-hour to learn Rust (2020)
#53Why do I love this language so much having never written a line of it? Something about it is just so damn aesthetically pleasing.
Re: A half-hour to learn Rust (2020)
#54Earlier quoted context omitted.
I get the impression that Rust revisions are (at least intended to be?) backwards compatible: [0] Are there are good workarounds when breaking changes to occur? No idea if/how well breaking language changes can be isolated to stay within individual crates. [0] https://subscription.packtpub.com/book/programming/978178934...
> I get the impression that Rust revisions are (at least intended to be?) backwards compatible I don't think that matters at all. If I try to build a new project with an older version of Rust, the compiler will still throw errors when stumbling upon newer features.
Usually when people worry about language evolution, the concern is that a newer compiler can't handle older code.
Re: A half-hour to learn Rust (2020)
#55I know this is not going to make me an expert in Rust. That'll probably take 10 years. But this is just the kind of thing I was looking for to get started with Rust. Thanks for sharing it here.
Re: A half-hour to learn Rust (2020)
#56Re: A half-hour to learn Rust (2020)
#57Can someone explain to me where the feeling_lucky variables comes from in the match example? I don't get it. The variable isn't defined anywhere in the relevant scope.
Re: A half-hour to learn Rust (2020)
#58I know this is not going to make me an expert in Rust. That'll probably take 10 years. But this is just the kind of thing I was looking for to get started with Rust. Thanks for sharing it here.
If becoming an expert in Rust had to take 10 years, that would mean there are currently not a single Rust expert in the world
Re: A half-hour to learn Rust (2020)
#59Earlier quoted context omitted.
> Without the let, I'd have to do a match statement followed by an unwrap just to check if a field in an enum is set. You... would not? An `if let` trivially desugars to a `match`. if let = { ... } becomes match { => { ... } _ => {} }
See my example. I am trying to extract the value of an optional field in the enum. That's where the unwrap comes in.
The snippet you link to should be replaceable by something along the lines of
match &passages.asset {
TranscriptionAsset::Track {
artist_name: Some(artist_name),
..
} => {
metadata
.entry(ARTIST_METADATA.to_string())
.or_default()
.push(artist_name.clone());
}
_ => {}
}
no `unwrap` needed. I don't know where you got that idea.Re: A half-hour to learn Rust (2020)
#60This is, more or less, how I learned Rust circa 2015 (might have been a couple years later). I quickly started to write programs like I would have in C but got completely thwarted by the borrow checker because I wanted pointers everywhere. This made me throw my hands up and leave for other languages. However, 8 years later I did eventually come to love rust after learning the One Weird Trick of using indices instead…