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)
71–80 of 86 posts
Re: A half-hour to learn Rust (2020)
#72 fn tail(s: &'a [u8]) -> &'a [u8] {
&s[1..]
}
...
fn main() -> Result {
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.Re: A half-hour to learn Rust (2020)
#73The YouTube channel "No Boilerplate" turned this into a 10-minute video version, for anyone that prefers video: https://www.youtube.com/watch?v=br3GIIQeefY
Re: A half-hour to learn Rust (2020)
#74fn tail (s: &'a [u8]) -> &'a [u8] { &s[1..] } ... fn main() -> Result { 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.
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.
Re: A half-hour to learn Rust (2020)
#75The YouTube channel "No Boilerplate" turned this into a 10-minute video version, for anyone that prefers video: https://www.youtube.com/watch?v=br3GIIQeefY
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=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
Re: A half-hour to learn Rust (2020)
#76half an hour to learn Rust, the other half to wait for compilation.
Re: A half-hour to learn Rust (2020)
#77I 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.
(I'm learning Rust by implementing a simple Lisp interpreter in it) I think TFA is a great resource in terms of presenting syntax and idioms. My biggest problem with learning Rust though has been understanding how to do things when the borrow checker prohibits the solution that would be 'obvious' in C#, C++, etc. I started to make progress when I bought the O'Reilly Programming in Rust book, and then thoroughly read…
Re: A half-hour to learn Rust (2020)
#78Earlier quoted context omitted.
You are confusing shortening with simplifying. The `if let` syntax is an unnecessary addition to the language so it is by definition an added complexity. Of course the resulting code is much easier to read and I definitely agree that it's a nice feature but I wouldn't pretend it made the language simpler, just more comfortable once you already know it.
Exactly what I had in mind, thank you for explaining it so succinctly!
Which, while it might arguably hurt adoption, is a good value proposition, since you spend a lot more time knowing the language than not knowing it.
Now, not everything is always perfect, and I agree that the `if let` is not the most useful part of the language, as it drives pointless discussions about when to use it vs match (some people prefer the esthetics of match even when an if let can be used, others prefer to use a if let whenever possible). This redundancy apart, the construct doesn't eat any mental energy once you know it. The same can't be said of many of C++ quirks (initialization rules, member-initializer list in constructors, the rule of five)
Re: A half-hour to learn Rust (2020)
#79Earlier quoted context omitted.
> I love the idea of Rust, but the language itself seems needlessly complex Well, I have to agree Rust isn't one of the simplest PL-s on the planet. This is due to the fact that it is quite a modern PL and quite a versatile PL, supporting elements of functional programming, trait-oriented (conditional generics) programming, asynchronous programming, etc. and a capable standard library on top of it all. It takes, inde…
> ...and quite a versatile PL, supporting elements of functional programming, trait-oriented (conditional generics) programming, asynchronous programming, etc. and a capable standard library on top of it all. Yes, exactly! Now can I have just a safe C without all the other stuff, pretty please? :) I understand Rust is not it, but I hope someone comes up with a simple PL which is also compile-time memory safe. I think…
Not sure how much we could remove from Rust while keeping the problem tractable. The borrow checker is needed for compile time memory safety sans garbage collection. For borrow checking to be tractable, one needs shared references, exclusive references, owned values, the possibility for reference counting, and the possibility for interior mutability. This mandates smart pointers, that pretty much mandate generics. These various abstractions also mandate a capable standard library, unless the language would hardcode all these abstractions, which would endanger the low-levelness of the language (since you wouldn't be able to implement your own abstractions for e.g. embedded contexts)
For the demarcation between unsafe Rust and safe Rust to work, one needs encapsulation, so field privacy.
For concurrency, the language requires a way to mark types as thread safe, which requires a way to say things about structures, so a least a weak version of traits.
A smaller version of Rust probably exists, but I don't think we could remove as much of the language as we could imagine at first without compromising safety. It also wouldn't be "just a safe C", because C itself has heaps of accidental complexity (e.g. the way function pointers are declared, integer promotions, implicit conversions, the antiquated textual inclusion compilation model that is prone to ODR violations and complicates build systems, array decay, and so on...) that would need to be removed.
Re: A half-hour to learn Rust (2020)
#80Earlier quoted context omitted.
That'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.
> 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 m…
You're now listing languages, such as Python, that don't have a specification, so it is unclear what your criticism actually is.
By python's standards, Rust is very good: a lot fewer breaking changes (changes are tested against the entire, huge, open source ecosystem to check if they are breaking, I think this level of testing is unparalleled), the release and versioning process is extremely clear (one minor release every six weeks, patch releases to address unexpected regressions + security issues), and it also have a really well specified evolution process through the RFC process.