2 ms·
> Who wants to constantly argue with the compiler as to whether or not he should be allowed to have parent/sibling/other pointers? You learn to structure your
by Manishearth 9y ago
> Who wants to constantly argue with the compiler as to whether or not he should be allowed to have parent/sibling/other pointers?
You learn to structure your code in a certain way. Design patterns from C++ will not necessarily carry over.
It certainly is painful to program in Rust if you design your code as if it were C++. In practice, the stuff you talk of doesn't end up being a problem; Rust still lets you do all that just that it's different.
- mehrdadn 9y ago>> Who wants to constantly argue with the compiler as to whether or not he should be allowed to have parent/sibling/other pointers? > You learn to structure your code in a certain way. Design patterns from C++ will not necessarily carry over. Er... data structures with parent pointers and sibling pointers are "design patterns from C++" to you?
- Manishearth 9y agoUsing move constructors to keep them updated is a design pattern. Most such datastructures either get implemented with Rc/Weak (which has a performance cost but often not a problem), or with "unsafe", which lets you write Rust as if it were more like C++ (you still have types, but you now also have certain dangerous abilities that you use carefully). Rust provides you the tools to properly abstract this unsafe such that it stays within the implementation and doesn't leak. This is true for Vec and BTreeMap, for example. You're talking about arguing with the compiler but unsafe Rust is not much worse than regular C++ in this aspect (there are some differences), so you always have the ability to drop down to this place where the compiler won't fight you to do stuff like this. Generally you can abstract away low level datastructures as unsafe code that's safe to use from the outside (this is usually something you can manageably audit) and everything else stays safe. Most such datastructures exist as libraries or in the stdlib already.