logoalt Hacker News

zbentley • today at 2:37 AM • 1 reply • view on HN

As a Rust enjoyer, there are plenty of examples of that--if I interpret GP's complaint as being more about explicitness than abstraction, which is what most new-to-Rust folks I've talked to about similar complaints turn out to mean.

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.


Replies

Maxatar • today at 3:10 AM

Sorry why do you have a Box wrapping an Rc? That doesn't seem common at all. You either use Box or Rc, but I can't see many use cases for both. But even if you do have a scenario where you use Box and Rc, then how would that fairly idiosyncratic use-case be different in C++? You want unique ownership of a shared resource (???) in Rust but somehow in C++ you don't want that for the same or similar use-case?

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.