by vor_ · 1w ago · 0 comments
I'd love an example of what you're talking about.
The natural representation of VecDeque<T,A> would be a thin pointer and three pointer-sized integers, on a modern PC that's 32 bytes.
And sure enough Rust's VecDeque<T,A> is in fact a 32 byte type. But there are indeed layers of abstraction:
VecDeque<T,A> is a WrappedIndex named head, an integer named len and a RawVec<T,A>
RawVec<T,A> is a RawVecInner<A> and a PhantomData<T> marker
The PhantomData is just the idea of T, and evaporates - it doesn't need any space but if you want to get angry about abstractions an evaporating type which makes the compiler work is exasperating.
RawVecInner<A> is that thin pointer, a Cap and the Allocator A. The Global allocator will also evaporate - although some customer allocators might take space here.
Cap, like WrappedIndex is "just" an integer and all the associated code to use that integer properly everywhere and not make clumsy mistakes.
Now, when you use VecDeque you don't care about any of this. It just works properly, and it's no bigger than it would be if it didn't have all this sophisticated machinery inside it, but if you are bothered just by the idea then that's going to drive you away from Rust (or indeed any modern language).
Box<Rc<Container<Type>> soup gets tedious. Writing higher order functions that take closures which manipulate data bounded by a related lifetime gets really tedious. Dealing with interleaved lifetimes can be a pain. Pin and async, if you're in that realm, gets tedious to write out. And the explicit notation of Send and Sync for types that, in a language like C++, would either encode their copy/ref-stability in the documentation of the type or leave it up to the programmer to handle, also gets tedious. As an inheritance lover (we exist!), having to rewrite the same/similar implementations or signatures across multiple traits and sprinkle my code with one-off enums to model a type hierarchy can also be a drag, doubly so if I'm using something that's not dyn-compatible.
Most of those things exist for good reasons, and I appreciate the capabilities provided by having them. But even as someone who likes the language, it remains tiresome to have to type them out.
I can sympathize with some of the things you call tedious in Rust, like the async issues, but I can't see how those wouldn't also be tedious in C++ using C++ coroutines, which are full of footguns and implicit lifetime issues. For Send/Sync, in situations where you need to explicitly mark a type as Send/Sync, in C++ you have the exact same issue as in Rust, but in C++ you have no way to communicate that property formally, so either you document that so people know if an operation is thread-safe, or you don't document it and people have to inspect the source code or worse, just guess.
Are you suggesting that's better than enforcing the property in the type system? Maybe if you're a solo-dev working on your own mini-project, it might be marginally better, but I'm not convinced.