6 ms·
A half-hour to learn Rust (2020)
- AlanSE 3y agoCan 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.
- steveklabnik 3y agoIt's not a full example, that code would not compile because that variable is not defined.
- deleted 3y ago[deleted]
- mstaoru 3y agofn tail<'a>(s: &'a [u8]) -> &'a [u8] { &s[1..] } ... fn main() -> Result<(), std::str::Utf8Error> { let s = std::str::from_utf8(&[240, 159, 141, 137])?; println!("{}", s); Ok(()) } Sorry, `|::|&(_Rust!){}?`. I know you're sexy. But I'll prefer my eyesight and sanity over you.
- dureuill 3y agoAs someone with bad eyesight, Rust has been very legible, and the sigils actually help for that (in the same way as most mathematical notations make formulae easier to parse). It does take a little while to get accustomed to, but the investment is more than worth it. Can't comment on my sanity though.
- gtani 3y agoHelps a lot to track toolchain improvements: - in distrib: cargo, analyzer, clippy - others: Aquascope godbolt intellij flowistry __________________________ https://www.infoworld.com/article/3267624/whats-new-in-the-rust-language.html https://www.infoworld.com/article/3267624/whats-new-in-the-r... https://github.com/cognitive-engineering-lab/aquascope https://github.com/cognitive-engineering-lab/aquascope https://intellij-rust.github.io/thisweek/ https://intellij-rust.github.io/thisweek/
- distcs 3y agoI 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.
- mcronce 3y agoIf you're already an expert in some other programming discipline (e.g. another language) I wouldn't expect it to take 10 years to become a Rust expert. I'd expect one or two if you're using it primarily, which is similar to what I'd expect for most other languages.
- zer0tonin 3y agoIf becoming an expert in Rust had to take 10 years, that would mean there are currently not a single Rust expert in the world
- steveklabnik 3y agoThere are dozens of us, dozens! (I started learning Rust ten and a half years ago. Anyway I agree with your point it's just amusing.)
- Keyframe 3y agoI cannot disagree with that.
- lucideer 3y agoI've been writing JS for 17 (continuous) years I'd say it took me at the very least 6, probably much closer to 10, to get to what I'd call "expert" JS knowledge (and have since regressed somewhat). I've been using other languages longer than 10 years too but not continuously enough to ever consider myself expert. I'd say there are definitely rust experts out there, but I'd posit it's unlikely for the average dev to have gotten that far yet.
- zygy 3y agoThe current Rust experts probably spent more than 10 years learning the concepts that made them Rust experts.
- molenzwiebel 3y ago(2020)
- CoastalCoder 3y agoThanks for pointing that out. As an utter newbie to Rust, I can't guess whether or not the tutorial has become dated.
- mhb 3y agoAnd has it?
- oconnor663 3y agoNo it's still good.
- rewmie 3y agoThat's perhaps the most pressing problem of Rust: not providing a concrete specification that can be targeted by projects and implementations.
- School-Cotton 3y agoThat's indeed a problem, but I don't think it's the most pressing one, since it's common to the majority of widely-used languages.
- rewmie 3y ago> since it's common to the majority of widely-used languages. I don't think so. Both C and C++ are specified in international standards. That's the gold standard. Java has very concrete versioning and specification process. Python is also exemplary in its release and versioning process. C# even breaks down versioning in terms of both CLR and fundamental frameworks. Exactly which widely used language do you think is missing from that list?
- jetpackjoe 3y agoThe YouTube channel "No Boilerplate" turned this into a 10-minute video version, for anyone that prefers video: https://www.youtube.com/watch?v=br3GIIQeefY https://www.youtube.com/watch?v=br3GIIQeefY
- noman-land 3y agoThis channel rules. Thanks for the rec.
- 0atman 3y ago(no boilerplate author here) Thank you so much for linking! When I was first getting started I learned so much from Amos and his INSANE deep-dives over at fasterthanli.me, basically he taught me Rust. For my 3rd video I messaged him and asked if I could base it on his article and he said 'go for it' - since then we've both found ways to go full-time in our respective worlds, and we shitpost in a private discord together :-D This video isn't really a good intro to either my channel or the WHYs of Rust, just the syntax. If I may signpost my own intro to Rust playlist https://www.youtube.com/watch?v=oY0XwMOSzq4&list=PLZaoyhMXgBzpr9Czgxj953GcUDkGlwa-Y https://www.youtube.com/watch?v=oY0XwMOSzq4&list=PLZaoyhMXgB... And an example of one of Amos's deep-dive videos "C++ vs Rust: which is faster?" https://www.youtube.com/watch?v=VMpSYJ_7aYM https://www.youtube.com/watch?v=VMpSYJ_7aYM
- artogahr 3y agoYour videos (and by extension you) are awesome and have been one of the biggest motivations for me learning Rust and continuing programming. Thank you.
- skulk 3y agoThis 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 of pointers.
- jandrewrogers 3y agoA lot of systems software, especially in C++ but perhaps less so in C, makes heavy use of indices too, for reasons unrelated to the borrow checker obviously. I always felt this should produce less friction in the adoption of Rust than it seems to since it is idiomatic for many types of C++ software.
- notyoutube 3y agoIsn't that one weird trick more or less defeating the whole purpose of rust's ownership/borrowing model by moving the problems one level up the ladder? Having seen that kind of opinion stated elsewhere, it seems what most people would like is rust minus borrowing, and I feel I would get behind that too.
- beezlewax 3y agoHow would memory management work without the borrow checker?
- gary17the 3y agoReference-counted[1], just like, say, Swift. [1] https://en.wikipedia.org/wiki/Reference_counting https://en.wikipedia.org/wiki/Reference_counting
- gary17the 3y ago> what most people would like is rust minus borrowing It's already possible. Use Rust reference-counted smart pointers[1] for shareable immutable references and internal mutability[2] for non-shareable mutable references checked at runtime instead of compile time. [1] https://doc.rust-lang.org/book/ch15-04-rc.html https://doc.rust-lang.org/book/ch15-04-rc.html [2] https://doc.rust-lang.org/book/ch15-05-interior-mutability.html https://doc.rust-lang.org/book/ch15-05-interior-mutability.h...
- Thaxll 3y agohalf an hour to learn Rust, the other half to wait for compilation.
- WilliamCarlos 3y agoWish there was a version of this for C++!
- nathell 3y agoAs a recent newcomer to Rust, I find Amos' articles an indispensable source of knowledge. His post on recursive iterators [1] has been a lifesaver while I was working on my problem. Thanks, Amos! [1]: https://fasterthanli.me/articles/recursive-iterators-rust https://fasterthanli.me/articles/recursive-iterators-rust
- karimf 3y agoPrevious discussion with 333 comments (2021): https://news.ycombinator.com/item?id=25610741 https://news.ycombinator.com/item?id=25610741
- dang 3y agoThanks! Macroexpanded: A half-hour to learn Rust - https://news.ycombinator.com/item?id=25610741 https://news.ycombinator.com/item?id=25610741 - Jan 2021 (330 comments) A half-hour to learn Rust - https://news.ycombinator.com/item?id=22448933 https://news.ycombinator.com/item?id=22448933 - Feb 2020 (148 comments)
- g4zj 3y agoAlso useful is the "Learn X in Y Minutes" page for Rust. https://learnxinyminutes.com/docs/rust/ https://learnxinyminutes.com/docs/rust/
- deleted 3y ago[deleted]
- trevor-e 3y agoFeels like every language should have an introduction like this. It's frustrating that lang intros are either your very basic and trivial example, or a full-blown set of tutorials, nothing in-between. I also chuckled at the "20 minute read".
- bornfreddy 3y agoThis might not be a popular opinion, but - I love the idea of Rust, but the language itself seems needlessly complex to me. It looks like the authors tried to cover so many esoteric usecases that the result is more like C++ than C (which is not good in my eyes). One example: > `let` patterns can be used as conditions in `if`: Anyway, this tutorial looks great, I'll give Rust another go when I have a good project for it, but to me it seems there is a great need for a simpler language with similar memory management. Rust is just too complex, imho.
- parentheses 3y agoThe problem with Rust is learning it for... > when I have a good project for it ... is a bad idea. I've heard this from several programmers who now use Rust professionally, but don't have first-hand experience about it. Their take can be boiled down to: Rust has a learning curve that will mean that the first version will invariably be throw-away. Developing a mental model for how to change memory management structures to please the borrow checker and properly encode ownership seems like the biggest hurdle to writing good Rust. I believe this is the main reason Rust adoption isn't skyrocketing, but still growing. The "onboarding" for Rust is more labor intensive and therefore disincentivizes its use.
- bornfreddy 3y agoI understand it will be a throwaway project, that's fine. But it helps me learn if I have a goal in front of me.
- brigadier132 3y ago> > `let` patterns can be used as conditions in `if`: You can code without that, it's just that you are going to wish you had it after your first few programs. > but the language itself seems needlessly complex to me A lot of the complexity is around making the explicitness of the language bearable. If you had to be explicit without all the syntax sugar and type / lifetime inference it would be insufferable to program in.
- trane_project 3y ago
- ramesh31 3y agoWhy do I love this language so much having never written a line of it? Something about it is just so damn aesthetically pleasing.
- _aaed 3y agoAll of this code is in safe Rust. Unsafe Rust is a different beast