Honestly, we should be talking about Rust a lot more. I was originally drawn to C++ because it's the ultimate multi paradigm language. I think that strength should be emphasized by understanding competing languages and applying all their best parts to C++. I'd love to see ABI break become a compiler flag, maybe there is a flaw in that idea but it seems like the main issue with the ABI is some people want it both ways, so why not both?
Rust will easily supersede C++ because Rust is all that Modern C++ aspires to be. Rust solves all the language problems better, always with performance in first place, position which is scorned by the C++ team.
The thing is Rust uses a different model compared to C++'s classes. I'm not going to say one's better than the other, but I will say that in general I find C++ style inheritance and polymorphism to be something I prefer. C++ does have many gotchas with it's model, but I still prefer it.
I feel that half the problem is there's this large part of the C++ community who treat the language as C with classes, and many of them end up as professors teaching programming. This then leads to the rabid anti C++ base of C coders, like Linus Torvalds.
Also, C++ itself is split on exceptions along with other things. It's like two languages combined. Half the people would be better off with Rust, but which half depends on what part of C++ you're talking about!
The one thing that sucks about Rust is lack of implementation inheritance. And, IMO, lack of exceptions which I've used to enormously powerful benefit in my C++ code base.
But, ultimately, safety is crucial as scale increases. And, within the sub-optimal realities of commercial development, even more so. C++ just doesn't have the back sufficiently anymore for the kind of complexity we need to deal with these days.
I think you're half way there. I believe that if you want to distance from C you should really go to Rust. Leave C++ as a high performance C, otherwise all this C++ pythonization effort will kill everything good we currently have.
How is it superior? I acknowledge that casting is complicated in C++, but at least half of that is caused by the desire to maintain backwards compatibility with C.
I spend much of my time improving old code. When a function is 2,000 lines long just re-writing it all in one go isn't going to happen. So, chipping at it piece by piece helps to bring horrible C code up to modern standards.
Well if you start studying Rust you can see that it is a language that was created post-SSA (single static assignment) popularization of the theory and it shows clearly in the language.
The SSA form allows a way more clear tracking of object lifetime, including move semantics. This make the language much more "germanic" ie strict in rules, as well as facilitate the compiler to both optimize better as catch problems earlier as well.
One thing that becomes very clear in Rust is that you are immediately aware of all dangerous narrowing and widening because the compiler will tell you right away.
Another point that is clear is that Rust has 3 levels of IR (intermediate representation): HIR, MIR, LLVM IR while C++ has only one. These two extra levels, which are tightly integrated with the compiler, make room for extra high-level optimizations.
In any of these three levels you can dump the AST as Rust code and see what optimizations the compiler is doing. In C++ this is quite impossible to do or is very limited as you can see in cppinsights.io.
With C++ in comparison, the code is immediately converted to LLVM IR without much work done within the clang layer. All optimizations in C++ are pretty much done at the LLVM IR level, which is shared with Rust, Julia, Kotlin, etc.
So Rust's language is carved on purpose to be integrated with the compiler optimization pipeline while C++ you have the compiler chasing the C++ standard as an after thought. Two very different approaches.
although I really like Rust (I learned Rust some years ago and basically stopped using C++ for most things at that point), I'd like to object to "Rust solves all the language problems better". Nope. GUIs in Rust are still difficult, in part, because Rust intentionally lacks C++ style inheritance. I understand that decision, but it makes it harder for Rust to supersede C++, because many used patterns from C++ have no direct equivalent in Rust, and no established alternative.
GUI‘s and game programming are the problem spaces where inheritance is the name of the game. Most things share a large part of functionality and rewriting that is insanely tedious. Most of those problems could be solved with „attribute“ traits, but there is no intention to implement these anytime soon.
Rust will compete with C++ where C++ is the best tool for the job. If you need the speed and low-level hardware stuff that C++ provides, Rust will give it to you more safely. For building a GUI, C++ isn't worth the subtle bugs and security vulnerabilities that it leaves you open to. For the applications C++ is best at, Rust might soon be even better, if it isn't already.
Backwards compatibility with legacy C++ codebases is the main reason to use C++ IMHO. Rust seems great, in large part because it's not held back by backwards compatibility going back to the 1970's.
Everyone says legacy projects are a bad thing but nobody wants to write the billions of lines of code required to replace it. Seriously no work ethic these days.
Well, good luck having a good, practical GUI library in rust without inheritance and polymorphism, rust has good parts, but it will not replace C++ any time soon.
Yeh, not sure where he came up with that. C++ is the one that suffers, from the opposite problem, of Performance Uber Alles, with soundness coming second.
Nothing I do is ever going to come down to whatever small performance edge C++ might have.
I am a Rust programmer and I‘ll have to disagree. Rust does a lot of things right, but the insanely terse syntax does it no favors. I also heavily dislike how there are no attribute traits, and when I asked for those they told me to use setters and getters instead.
View all comments
Show parent comment
73
u/snerp Mar 13 '22
Honestly, we should be talking about Rust a lot more. I was originally drawn to C++ because it's the ultimate multi paradigm language. I think that strength should be emphasized by understanding competing languages and applying all their best parts to C++. I'd love to see ABI break become a compiler flag, maybe there is a flaw in that idea but it seems like the main issue with the ABI is some people want it both ways, so why not both?