4 ms·
How do you do anything dynamic/cyclic? Like, graphs that need to be updated in runtime?
by atemerev 3y ago
How do you do anything dynamic/cyclic? Like, graphs that need to be updated in runtime?
- goku12 3y agoMy experience is that most programs dealing with ordinary problems don't need such complicated data structures. In cases you do, Rust has a few options: 1. Use Rust's runtime safety checks, using Rc, Weak, RefCell, etc. It will be as ergonomic as GC'ed languages (no productivity loss). While this has a runtime performance penalty, it will still be mostly comparable to other languages. This works for most use cases. 2. If you need the last ounce of performance, just drop all automated safety checks and do it manually using unsafe. Even if you make a mistake, your debugging will be limited to the unsafe blocks. This approach isn't unusual in Rust. 3. Use either the standard library or something on crates.io that does what's given in 2. Rust's generics make it easy. This resource deals with these topics in-depth: https://rust-unofficial.github.io/too-many-lists/ https://rust-unofficial.github.io/too-many-lists/
- atemerev 3y ago1. Option 1 quickly degrades into unrefactorable mess of TypedArenas, nested Rc<RefCell>>, lifetime annotations everywhere, and the like. It is unmanageable, which is why even libraries like PetGraph do not use it. 2. No, I don't need every last bit of performance. C++ performance is OK. Or any other sane language like Nim, Crystal, etc. I need async, though, which is yet another hell in Rust. 3. This absolutely can't be done with standard library. There are libraries like PetGraph, which solve this particular problem (by some very unobvious approaches and bits of unsafe code), but there are many problems like it which don't have any libraries for it yet. I do have hard problems. I want a language which makes hard problems easy, and impossible problems hard. Rust is definitely _not_ such a language, and it makes me like 5 times less productive, and sucks all joy out of programming.
- xtremegoose 3y agoUse one of the many libraries that have safe abstractions over unsafe code? I don't know why people think you need to roll your own? I guess that's just what people do in c/c++, doesn't seem very productive... https://docs.rs/petgraph/latest/petgraph/ https://docs.rs/petgraph/latest/petgraph/
- atemerev 3y agoThere are definitely no less libraries for C++. I am a scientific software engineer, and occasionally I do develop new things. And Rust makes writing new system-level software way harder, which I don't understand, as it is a system-level language.