Re:I've just learned Rust and I think I'm in love
by urschrei on Friday March 30, 2018 @01:16PM
(#16717927)
The difficulty of writing self-referential data structures in Rust arises on HN often. Every time, the answer is, broadly, the same:
- It is certainly difficult
- Strategies and approaches from low-level languages which are at least cosmetically similar will probably be unavailing
- In some (many?) cases, crates (Rental, Petgraph, Spade) exist that already implement them. Their design can be studied
- There's an entire book (http://cglab.ca/~abeinges/blah/too-many-lists/book/) devoted to writing linked lists in Rust. It's highly informative
Without wishing to explicitly criticise your approach to learning Rust, I'll note that for the vast majority of programmers, it's likely to be frustrating for quite a while.
Re:I've just learned Rust and I think I'm in love
by whyever on Friday March 30, 2018 @02:31PM
(#16718612)
It is really not difficult if you go the petgraph way. Just use a vector and indices into it instead of references.
Re:I've just learned Rust and I think I'm in love
by username223 on Friday March 30, 2018 @06:58PM
(#16720508)
That's sort of depressing. "Just make your own virtual memory space to get around Rust's PITA memory management" sounds like giving up.
Re:I've just learned Rust and I think I'm in love
by OtterCoder on Saturday March 31, 2018 @10:33AM
(#16723445)
If you don't want to manage memory, why are you using any systems language? Python, JS, Go, and any number of other languages will be much kinder to you.
Re:I've just learned Rust and I think I'm in love
by username223 on Saturday March 31, 2018 @11:35AM
(#16723692)
What I meant to say (hence the downvotes...) is that Rust's "borrow checker" is enough of a nuisance that this graph library replaced memory addresses, i.e. pointers, with indexes into an array, effectively creating its own virtual address space.
Re:I've just learned Rust and I think I'm in love
by oconnor663 on Friday March 30, 2018 @01:18PM
(#16717944)
Worth noting: Many of the examples in that book that required unstable/nightly at the time, now work on stable Rust.
Re:I've just learned Rust and I think I'm in love
by v_lisivka on Friday March 30, 2018 @01:18PM
(#16717955)
See [0] for example.
0: https://doc.rust-lang.org/src/alloc/linked_list.rs.html#46-5...
When I try to learn a new language, I typically want to: (a) read a lot of code people have written in that language and (b) implement algorithms that I understand well, while keeping in an idiomatic style.
When I tried to do this with Rust, I was shocked by how difficult it was to implement certain algorithms (specifically, operations on Linked Lists and Graphs). Maybe I'd do better if I chose a small project to work on, but it disturbs me to know that such elementary problems are so difficult to solve.