4 ms·
Ouch! > Rust does slightly better than C++ by enforcing trivial moves, at the cost of making many useful programs impossible to write. What "useful" programs
by worik 3y ago
Ouch!
> Rust does slightly better than C++ by enforcing trivial moves, at the cost of making many useful programs impossible to write.
What "useful" programs fit a useful definition of "many"?
It makes self referential looped data structures hard to write (double linked lists, trees with pointers to parents).
No loss. Great improvement to have fewer of those
It makes arbitrary allocation hard. Enforces behaviors. Makes a programmer think very hard.
"useful programs impossible to write. " No it does not. It ,ages a lot of bad ideas hard to implement, makes nothing "impossible "
- o11c 3y agoGood luck implementing "peer pointers" in Rust. Zero allocation involved, trivial to do safely in C++. class A { /* can be NULL if detached */ B *peer; /* other fields generally exist in one of the classes. */ /* useful objects are typically created in pairs, but can be constructed detached if needed */ /* move ctor and swap keep the (value) objects pointing at each other */ /* move assignment and dtor call detach() on the overwritten/expiring object */ /* Often separate "detach and cancel" and "detach without canceling" are useful */ void detach(); /* other functions specific to the peerage */ }; class B { A *peer; /* same API as `class A`, but usually most of it is only used via one owner. */ /* In my experience, generally one class's instance goes in some collection of centralized objects like an event loop, and the other is used as a handle to it. */ }; I guess we could always use the usual Rust solution of "screw ownership and efficiency, just shove everything in an `Rc<RefCell<>>`".