by zarzavat · 1d ago · 0 comments
AI makes it easier to write new code in Rust, easier to rewrite old code from C++, and easier to exploit C++ code.
There's no way back for the language, inertia will carry it for the next 10+ years but its eventual irrelevance is a certainty.
LLMs are quite good at hand-written assembly though, so my C++ library still has a large lead for platforms where that work is done. I can probably port that to Rust as well, but I did start out with forbid(unsafe).
The Rust version is currently middle of the pack. But it's in my view a success. The trick to getting good performance with tailcall dispatch in Rust is keeping the argument list low enough to fit in the calling convention, on stable. For nightly the "become" keyword is faster as I can put a few things in the stack frame to speed things up even more.
I'm not sure how to improve the Rust performance anymore than this, other than trying to go for cheap wins in the bytecodes themselves. The only big lever left is hand-written assembly, which I may have mentioned exists in the C++ version, hence the outrageous performance.
> …it was completely painless and ~same performance. LLMs found a swathe of issues that I ended up porting back as well.
It's a language I know, and I'm unlikely to learn ins and outs of Rust with LLMs around, neither are other devs stitching to Rust either I reckon.
In this scenario I really don't see a compelling argument to switch.
It's true the compile times are often higher, but if you split crates aggressively and only use release builds when you really need to, the difference isn't that big.
I don't see much need for Rust in a world where LLMs are significantly better at avoiding C++ footguns than humans have proven to be. It's fine but no longer mandatory for safe/secure coding. A C++ programmer who doesn't already know Rust probably won't need to.
We have some of our country's most powerful supercomputers, and the people supervising them don't know any Fortran. Last century's Fortran books from their predecessors are still here, but "My Fortran doesn't work" is going to get you the same odd stares as "Why can't I pay with farthings?" or other stuff that hasn't made sense for decades. [The farthing is about £0.001 and thus it was already basically worthless when it was formally demonetized in 1961]
There are occasionally interesting new developments in Fortran, like this https://dl.acm.org/doi/10.1145/3784828.3785257
It’s a domain-specific language at this point.
Atmospheric model that no one wanted to rebuild, due to the obvious complexity.
So while no one where I work knows Fortran either, we have people who know R and so are dependent on Fortran by association.
The machine already knows the CPP core guidelines better than any human, so you won't be able to drop in on a project as a consultant just from knowing the language well.
There's a project I once worked on that would be unfeasible to rewrite because there is so much unwritten about how it should perform - there are too many features and targets to test exhaustively. But that company already did layoffs pre-AI, because it already didn't take many devs with domain knowledge to keep it ticking. That project won't demand much language support and an industry of these projects won't be desirable to work in.
We’ve seen recent examples of fairly rapid complete rewrites into other languages using AI. That’s only going to get better.
Rust isn’t a panacea but it solves a class of critical problems around memory safety and concurrency. AI has made those factors even more important. At the same time AI makes Rust easier to write, which has always been an issue.
I just vibe coded a video processor in c++. it got really great performance compared to a commercially available thing in C#. I had hoped to be able to port it to rust for safety. No matter what I did it was always a 10-15% penalty. I settled on running TSAN and ASAN as part of the testing cycle.
The surrounding UI can definitely be rust, but as far as the hot paths for moving frames around, no.
I find that surprising, since ultimately Rust uses LLVM to emit machine code, same as a lot of C++. Do you have links to benchmarks? (Not asking to be a sea lion, just genuinely interested and I'd like to learn more about how or why that'd be.)
it's very close, but c++ still seems to have an edge.
> I'm trying to play with the "k-nucleotide" benchmark, described at https://benchmarksgame-team.pages.debian.net/benchmarksgame/.... Its input and output files, and the current fastest Rust-based implementation, are in this folder. Can you write a faster Rust version?
It came up with this (with no "unsafe"): https://paste.lol/kirk/kn_fast.rs
...with these hyperfine benchmarks:
Benchmark 1: bin/kn_rust (15 runs)
mean ± σ min … max
Wall Time 361.2 ms ± 5.8 ms 352.8 ms … 371.8 ms
Memory 134.7 MiB ± 0.6 MiB 133.7 MiB … 135.7 MiB
Benchmark 2: bin/kn_fast (15 runs)
mean ± σ min … max
Wall Time 98.3 ms ± 3.9 ms 92.0 ms … 103.8 ms -72.8% (3.7x faster)
Memory 67.1 MiB ± 2.2 MiB 63.8 MiB … 70.2 MiB -50.2% (2.0x less)
It's becoming increasingly hard to say "language A is faster than language B", especially when they use the same backend.For extra giggles, I'm telling Fable to make the C++ version faster, too. I wonder how close it'll end up to the Rust version.
There is also C++ Builder, however VCL and Firemonkey are actually implemented in Delphi.
Now if you mean Qt, yeah that is right.
You can rewrite but that is very different
And yes I have seen the OS projects that did a port by having six developers spend triple their usual time on the project for a year...
Anders has created or built four programming languages in less time than Bjarne has been Sunk Costing his one and I wonder sometimes where we would be if he had given up and started over.
If anything, the concept of caring about the programming language something is implemented in might be dying.
So while it isn't dying per se, it isn't the scale that used to keep The C/C++ User Journal's articles going.
Do you have good data on that?
The game industry is huge and, yes, many tentpole AAA games are written in C++. But there are a lot of games written in Unity and C# or other languages. I would be very interested to see what the relative breakdown looks like of where gamer dollars are going into which games by programming language.
You can also mix things up. I had OpenGL for the login screen for a while, and Vulkan for in-game. No particular reason other than a transition.
Just saying. C++ will soon have no moat in video games anymore.
But, what ABI precisely ? There is nothing a consumer can truly depend on since it is never truly defined. All libraries which truly offer ABI compatibility as a contract just leverage the C ABI.
C++ committee should have permitted their "mythical C++ ABI that exists but not really" to break across odd standard releases (once every 6 years) so to fix severe and glaring deficiencies in the standard library. This was done so successfully in the past and compiler vendors had no issues doing so. But in the last decade, the C++ committee has sadly gotten ossified and even tyrannical.
MANY prominent developers and committee contributors have walked away from the C++ standardization process (WG21) or pivoted away from C++ altogether after their major proposals were rejected or stalled. Most of them have moved away from C++.
And Rust will now rule the roost while C++ slowly petrifies and dies.
"Rubigina in pace, C++"
1. ABI differences between compilers - or even compiler version - for the same functions or data structures.
This is not so much an issue on modern platforms. Unix platforms generally use the Itanium ABI. MSVC uses the x64 ABI. You only have a problem if you're mixing MSVC and GCC/Clang binaries on Windows. (It's possible, but you need to follow the COM guidelines.)
2. ABI differences between libraries or library versions.
std::string, for example, has different members or data layout in every C++ standard library (GCC's libstdc++, Clang's libc++, Microsoft STL, etc.) That's why they are not binary compatible, even if you would compile them with the same compiler.
If a library changes the members or layout of one of its library types, that would be an ABI break within the library. This has nothing to do with the C++ ABI.
---
When the C++ standard people talk about ABI breaks, they typically mean the second kind.
That being said, I generally agree with you! It's ridiculous that the layout of library types - which often dictates the implementation - shall be set in stone once and for all, with no possibilities for future improvements.
As you said, there have been ABI breaks in the past, most notably between C++98 and C++11. Some things just need to be fixed. We shouldn't be held hostage by people who are forced to use ancient prebuilt binaries where the source code has been lost or the vendor has gone bancrupt. If they can't rebuild their libraries, they can put them in a separate component, possible behind a C interface.
It's always been like that. The ability to use a win32 gcc-compiled .dll and a MSVC-compiled .dll was something that was decided upon by the compiler devs not dictated by a standard. And even then not actually guaranteed - plenty of options or attributes to change that in incompatible way. And make sure you link agains the same windows CRT - hope you don't mix ucrt and msvcrt.
This used to be a much bigger problem, but it really isn't today.