| ▲ | smj-edison 2 hours ago | |||||||
This is perhaps a different take, but one reason I love Zig and C is because I've learned how to reason in pointers. I've worked with Rust in the past on a ~12,000 LOC side project, so I was all in with tree ownership and XOR mutability. But it turns out there's all sorts of delightful data structures that you can only express with unsafe in Rust. Intrusive doubly linked lists are the coolest thing ever. The fact that I can have a LRU cache that changes what's at the front by shuffling some pointers, while still keeping stable addresses so the hash map stays stable? That's freaking cool. Atomic operations with pointers for linked lists is really slick for implementing an allocator's free list between threads. Being able to walk a live heap using a breadth first search by just... following pointers, made the elegance of Dijkstra's algorithm come alive. Now, maybe I'm only running into these algorithms because these are the problems I'm running into, but in the Rust community I consistently got the message that linked lists were a legacy data structure. In some cases they are, but when they do apply they do so brilliantly. I know working in Zig leaves plenty of room for memory unsafety. Perhaps that's a bad thing. But I'm implementing an interpreter, and these algorithms are essential for it to run fast. I really do need to be aware of where every allocation happens, and what instructions the computer is running. So for now I stick with Zig, even though I know I'm opening myself up to memory exploits. | ||||||||
| ▲ | afdbcreid 2 hours ago | parent | next [-] | |||||||
I absolutely agree learning C is a good thing! In fact, there are two camps of Rust people: one that argue that you should not learn C before learning Rust, and one that argues that you should. Also, while such data structures/algorithms are rare, and more importantly, they can be written once and used many times, someone still needs to write them! Here is some online content on this side of Rust: - Learn Rust the Dangerous Way - https://cliffle.com/p/dangerust/ - Learn Rust With Entirely Too Many Linked Lists - https://rust-unofficial.github.io/too-many-lists/ - The Rustonomicon - https://doc.rust-lang.org/nomicon/ | ||||||||
| ||||||||
| ▲ | nitros 2 hours ago | parent | prev | next [-] | |||||||
> But it turns out there's all sorts of delightful data structures that you can only express with unsafe in Rust. Intrusive doubly linked lists are the coolest thing ever. I don't mean this to be a gotcha, but I think it's important to say that we can have these in rust too! The only difference is that the first thing we have to talk about is you the user can go about using an intrusive collection correctly. I love the cordyceps crate for this. If you want to be able to use your type as a linked list node, you must implement a Linked trait, the documentation of which clearly explains how to use it safely: https://docs.rs/cordyceps/latest/cordyceps/trait.Linked.html | ||||||||
| ||||||||
| ▲ | conradludgate 2 hours ago | parent | prev [-] | |||||||
Given your performance concerns, I'm imagining you're unlikely to run Zig-Fil in practice, due to the GC overhead? | ||||||||
| ||||||||