Hacker News new | ask | show | jobs
by pornel 45 days ago
It's been over 10 years since Rust 1.0 was released, and C programmers still see it as a new fad. Yet, the same article mentions, but fails to connect the dots, that even the large slow-moving corporations bankrolling the foundation have already adopted Rust and are leaving C as fast as they can.

It's a typical C mindset that rewriting programs creates new bugs, because it takes years to "battle test" and shake bugs out of a C program. In my experience rewrites in Rust uncover latent bugs of C programs when they finally get checked lifetimes, useful type system, enforced error checking, etc.

2 comments

That's not how rewrites create new bugs. It's not type or lifetime or error checking bugs, for the most part. It's "sometime in the ten years that this code has existed, someone ran into this weird corner case. This little detail right here fixes it. But the guys doing the rewrite weren't around ten years ago, and they don't know that the corner case even exists, so they don't know which specific details of the existing code they need to preserve." And so the handling for corner cases gets lost.

Doing a new implementation that preserves all of the features of existing code in all scenarios is really hard. The re-implementation team never knows all the scenarios that matter.

Is AI going to fix this? AI won't know all the scenarios and corner cases, either.

1:1 rewrites from C are perfectly doable. You can use C FFI and rewrite function by function, bug for bug, while checking snapshot tests. I've converted a few libraries this way, before AI. I caught C bugs this way, and then was able to further refactor and improve the Rust version. In the end, I'm super happy with the results and I'm never touching autotools or cmake again!

The pool of C software worth rewriting is shrinking. There are the few too-big-to-rewrite projects that will never move, but everything else is either getting rewritten, or has more modern replacements already written directly in Rust.

I can't vouch for LLM-assisted rewrites. The results can be randomly dodgy regardless of what you're writing or rewriting. I suspect we'll get plenty more LLM rewrites anyway, and people will just compensate by sending LLMs hunting for bugs by brute force.

If you do a line-by-line rewrite, then my comments don't apply. If you do a clean-sheet rewrite, or even a function-by-function rewrite, then they do.
In fairness the rewrite of coreutils into Rust has been pretty chaotic. Lots of bugs in the new code that weren't there in the old, including security bugs.
It also did find bugs in the old code and contributed tests to their suite.
They also copied some of our code, which is not very appreciated.