Hacker News new | ask | show | jobs
by skavi 55 days ago
unfortunately, It Depends.

different people struggle with different things. your existing experience is a major factor. there are a lot of concepts in rust that you may have already figured out in another language.

personally, i started learning rust two years after i started programming. at that point i had basic experience with c, c++, and some assembly.

i struggled with pretty much everything. i recall traits being particularly confusing. i’m not sure i fully got them until i messed with typeclasses in haskell at some later point.

but, honestly, i don’t remember struggling too much with lifetimes. i think the compiler is pretty good at suggesting fixes for common issues. i think it was helpful that i knew what a pointer was and had debugged segfaults. also, i didn’t really have an existing way of structuring programs that i was trying to reconcile with rust.

Box, Arc, and Rc you’ll figure out as you need them. you can think of them as tools which let you escape lifetimes.

Pin you won’t need to think about for a very long time [0]. You should check out my guide [1] if you’re interested though :). There are many others.

[0]: unless you’re the guy i’ve tasked with fully understanding FuturesUnordered as his very first introduction to Rust, lmao.

[1]: https://github.com/soooch/async-intuition/blob/main/src/pin_...

2 comments

How are traits not intuitive?

All they do is guarantee that a type has methods A,B,C available.

What might be slightly confusing are trait bounds on generics. They are kind of like traits themselves but not exactly. They implicitly say "this generic parameter must make methods A, B, C available via Trait X".

The answer to all forms of "How is [X] not intuitive?" is that the person finding it unintuitive doesn't have other points of reference that make it intuitive. Lots of people have spent their programming life working with languages that don't have the concept of generics, or maybe have even worked on things where they were using generics but didn't know that's what they were doing.

Very few things are truly intuitive, they just happen to be similar to other things you've done and so you've got a step up on understanding them. Really good software engineers tend to be constantly playing with things outside their usual domain and so have broader range of concepts they can reach for when the time comes.

because i was stupid lol. i’d only done (very) basic duck typed generics in c++ before then.

all i wanted was to add a new method i could call in the same way as all the methods on Iterator (map, filter, etc.). and was suddenly confronted with `impl Trait2 for T where T: Trait1`. which makes perfect sense now. but at the time was unparseable.

Traits are confusing if you came from C or Python but they work a lot like interfaces in Java or some other class based OOP language. Until you get to the difference between impl and dyn, that is.
for my own sake, i’ll note that i started learning rust in 2020. i’m no longer confused about Traits.