3 ms·
First off, thank you for all of the work you've put into Rust! I think the challenge that you face is that if the problem is CS101 courses, then Rust will alwa
by lumost 6y ago
First off, thank you for all of the work you've put into Rust! I think the challenge that you face is that if the problem is CS101 courses, then Rust will always be unfamiliar to the majority of practicing professionals.
Cyclic/recursive datastructures are common in web services, where one needs to model bidirectional relationships ( just think of friends on a social graph ). As well as several primitive datastructures such as the O(1) LRU cache.
Checking the Rust docs out, a dev who encounters this problem for the first time will eventually need
- "Reference Cycles Can Leak Memory" https://doc.rust-lang.org/book/ch15-06-reference-cycles.html https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
-- caveat: what if ownership is truly bidirectional?
- "unsafe" https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
- 5 different primitive lists which don't tell you how to make a friends graph: https://rust-unofficial.github.io/too-many-lists/infinity-double-single.html https://rust-unofficial.github.io/too-many-lists/infinity-do...
- Someone elses attempt: https://rcoh.me/posts/rust-linked-list-basically-impossible/ https://rcoh.me/posts/rust-linked-list-basically-impossible/
- Careful reading of the LinkedList implementation to see that unsafe is probably the best approach: https://doc.rust-lang.org/beta/src/alloc/collections/linked_list.rs.html#38-43 https://doc.rust-lang.org/beta/src/alloc/collections/linked_...
I'm a little biased on this front, when I first picked up Rust I chose to tackle an O(1) LRU cache as a quick learning exercise. I ended up beating my head against a wall for 20 hours. However on my current project I'm analyzing the wikipedia dataset ( another bidirectional structure ).
It would be useful to have a canonical/standard way to address such programming tasks other than "don't" - particulary if the way to address them is substantially different from what someone would have learned in a different language.
- steveklabnik 6y agoYou’re welcome! Do you really think the majority of professionals have CS degrees? I’m not so sure. And beyond that, it would have to be “a majority with a degree” and “a majority that choose to implement data structures as an initial/early task.” I’m really not convinced the numbers actually play out that way.
- lumost 6y agoHmm playing off my own anecdote - I do not have a formal CS degree, but I ended up taking courses and reading a few of the typical books later on. I think while my early experience biased me, the pain would have happened at one point or another eventually. I'd be surprised if the majority of web devs, and data science folks exploring rust wouldn't hit this problem at some point or another. As an example, one could easily run into this problem while writing an wiki,instagram, or twitter clone!
- steveklabnik 6y agoSounds like we're opposing anecdotes; I do have a CS degree, but didn't try to start with data structures. You may want to use something with those characteristics, sure, but that doesn't mean most users start by trying to implement, rather than use something existing.