5 ms·
> Just my 2p for others learning: for me, Rc::RefCell was what I was missing, even after I thought I was up to speed. I started (and then stopped) learning Rus
by cyphar 10y ago
> Just my 2p for others learning: for me, Rc::RefCell was what I was missing, even after I thought I was up to speed.
I started (and then stopped) learning Rust a few months ago (before their docs rewrite) and the borrow checker and concepts weren't explain in a way that I could understand. Programs wouldn't work at all, and when I read about Rc::RefCell I was scared because I wasn't sure how much garbage collection rust would do and whether or not it would actually be safe.
So yeah. Rust definitely has problems for beginners.
- steveklabnik 10y agoTo be clear, Rust has no garbage collector, and unless you type "unsafe", it's safe. RefCell will panic when something goes wrong. I should take this opportunity to mention that the book has been stagnating because I (along with Carol Nichols || Goulding) have been re-writing it out of tree: https://doc.rust-lang.org/stable/book/ https://doc.rust-lang.org/stable/book/ The ownership/borrow checker stuff has been completely re-done. The existing book chapters explain it in the abstract; in the new book, we use String/&str as a motivating example, since that's an area that often trips up new Rust programmers.
- simcop2387 10y agoThat's great to hear. That's definitely an area that has made me slow down on learning Rust. Will definitely be checking out the new book once it's ready.
- wyldfire 10y ago> So yeah. Rust definitely has problems for beginners. IMO Rust has the challenges that are very similar to all other languages have. But if you are trying to make the leap from a GC'd language like Java or Python to Rust without ever having written C/C++, you should expect to have to learn not only new language concepts but new programming concepts.
- deleted 10y ago[deleted]
- cyphar 10y agoI'm a programmer that has been using C for at least 8 years, and I've been developing in Go for the past 4 (as well as a couple of years of Python here and there). The point is that I have experience in quite a few programming languages, and I am familiar with the programming concepts you're referring to. I do not agree that Rust's challenges are the same challenges with other programming languages. Because Rust will not let you even play with the langauge unless you understand how to write safe programs (which is a concept that is defined in Rust). So there's a whole bootstrapping problem of "how the hell do I play with this thing to understand it if I can't play with it until I understand it fully". C, C++, Python, Go -- none of them have this issue. They will let you write bad code and won't stop you from running it (which I admit is not a good thing, I'm just saying that Rust's strengths are not without their downfalls).
- mikekchar 10y agoI had a similar problem with the type system in Haskell. I'd look at Haskell code and it was obtuse to me. Even reading books, it was hard for me to understand some stuff until I started writing code... but writing code was difficult because I didn't understand it. For me the key was just doing toy problems over and over again. Without understanding the idioms, it's hard to dive in and write something real. I think Rust is approachable if you take it like that (or at least it was when I looked at it about 2 years ago).
- Manishearth 10y ago> I wasn't sure how much garbage collection rust would do Rust doesn't do magical garbage collection. Rc<T> does reference counting, which is a form of garbage collection, but you get to choose where it gets applied, so it's a linear cost with no magical GC pauses or whatever. Rc isn't unique to Rust, it exists in C++ too. RefCell makes mutation within an Rc safe. It panics if you misuse it. http://manishearth.github.io/blog/2015/05/27/wrapper-types-in-rust-choosing-your-guarantees/ http://manishearth.github.io/blog/2015/05/27/wrapper-types-i... has more on the Rc<RefCell<T>> pattern
- alblue 10y agoReference counting is not a form of garbage collection. Both reference counting and garbage collection are types of automatic memory management.
- Manishearth 10y agoThis discussion crops up each time reference counting is brought up. In academia reference counting generally falls under the umbrella of GC. In the industry "GC" usually means "tracing GC". The terminology is irrelevant to the point I'm making. I did make a distinction between RC and the "regular magical kind" of GC.
- alblue 10y agoGarbage collection requires a garbage collector, which reference counting doesn't have or need. This is true for both academia and industry.
- xorxornop 10y agoIt's still runtime memory management. That makes it garbage collection in my book. Sure it's not as involved as tracing, the prototypical form of GC, but it's still something that requires a runtime check each time that resource is used or a binding to it goes out of scope, similar to aspects in generational GC.