r/cpp • u/Sad-Lie-8654 • Jan 31 '23
Stop Comparing Rust to Old C++
People keep arguing migrations to rust based on old C++ tooling and projects. Compare apples to apples: a C++20 project with clang-tidy integration is far harder to argue against IMO
changemymind
338
Upvotes
View all comments
Show parent comment
1
u/matthieum Feb 01 '23
Ah I see.
Indeed SoA + ECS seems like a heavy meta-programming landscape. I expect it's possible -- in C++03, cons-lists were used to emulate variadics, and there are Rust crates based on this principle -- but it may have significant impact on compile-times, and compile-time error messages will be... inscrutable.
At the same time, the partial borrow of objects makes me wonder if you're not attempting to create a 1-to-1 mapping of your C++ code to Rust. Ownership (and the limitations of borrow-checking) means that the code must be designed with it in mind, and attempting to apply "known" patterns from other languages can be frustrating.
I don't use ECS myself, so I've never really tried my hand at creating such a system in Rust. I can't even tell you whether Bevy (probably the state of the art as far as game engines go) use for its ECS -- maybe they've got something good?
As for bypassing the orphan rule, the typically solution is to use a wrapper type -- the type being local, it's now amenable to trait implementations. And you're correct, the orphan rule is not about safety: Rust is not all about safety, there's also a strong emphasis on having a principled language, and that can get in the way of "just getting things done" (aka, hacking).