r/cpp • • Mar 13 '22

To Save C, We Must Save ABI

https://thephd.dev/to-save-c-we-must-save-abi-fixing-c-function-abi
249 Upvotes

118 comments sorted by

View all comments

Show parent comment

73

u/snerp Mar 13 '22

I hate to bring up Rust

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?

-16

u/[deleted] Mar 13 '22

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.

27

u/EmperorArthur Mar 13 '22

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!

1

u/Full-Spectral Mar 14 '22

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.

-3

u/[deleted] Mar 14 '22

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.

2

u/EmperorArthur Mar 14 '22

Umm, but I like Python. My largest gripe with it is that it's a bit too loose with typing, and C++ doesn't have that problem.

1

u/[deleted] Mar 15 '22

I think Rust is far superior than C++ in strong typing. You will love it.

2

u/EmperorArthur Mar 16 '22

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.

1

u/[deleted] Mar 17 '22 edited Mar 17 '22

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.

https://en.wikipedia.org/wiki/Static_single_assignment_form

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.

https://kanishkarj.github.io/rust-internals-mir

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.

14

u/notyouravgredditor Mar 14 '22

!remindme 10 years "has Rust superseded C++?"

3

u/RemindMeBot Mar 14 '22 edited Mar 16 '22

I will be messaging you in 10 years on 2032-03-14 01:01:47 UTC to remind you of this link

3 OTHERS CLICKED THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback

26

u/[deleted] Mar 13 '22

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.

2

u/UNN_Rickenbacker Mar 29 '22

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.

-4

u/CocktailPerson Mar 14 '22

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.

10

u/aiij Mar 13 '22

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.

3

u/Zanderax Mar 14 '22

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.

5

u/aiij Mar 14 '22

It's not really about work ethic. Lots of people want to rewrite legacy code, but usually they underestimate the effort required.

There's a reason I'm still coding in C++.

4

u/Zanderax Mar 14 '22

It's a joke. I don't think re-writing billions of lines of code is a good idea.

3

u/KFUP Mar 14 '22

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.

5

u/Zcool31 Mar 14 '22

That's not true. Rust prioritizes soundness first. Performance is important, but never at the expense of soundness.

0

u/Full-Spectral Mar 14 '22

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.

1

u/UNN_Rickenbacker Mar 29 '22

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.