| ▲ | malisper a day ago | |||||||
I made a comment about this yesterday[0], but there's been a massive increase in people migrating from C to Rust due to LLMs. In contrast to what the C to Rust migration book is recommending (using FFI to integrate Rust with C), I've found it much easier to start from scratch. I recently finished a project where I rewrote Postgres in Rust[1]. For context, Postgres is about one million lines of C code. On one attempt, I tried using c2rust to convert Postgres into unsafe Rust code. That attempt succeeded in terms of getting working "Rust" code, but any attempt to change any piece to safe rust, would require thousands of changes across codebase. Even though I had working Rust code, I found it infeasible to get to working idiomatic Rust code. Instead what I found to be more effective was starting a new codebase and rewrite each file from the Postgres codebase into Rust one at a time. This allowed me to guarantee that at all times the new codebase was idiomatic and simultaneously I could make one pass over the Postgres codebase to get working idiomatic Rust. YMMV, but I found it way easier to generate a whole new codebase from scratch rather than incrementally rewrite an existing codebase. | ||||||||
| ▲ | KevinBongart a day ago | parent | next [-] | |||||||
Mainmatter head of engineering here. From what we've seen on real projects, I can confirm that asking an AI to migrate the code results at best in somewhat functional but unmaintainable code, and starting from scratch is a better approach… However, starting from scratch doesn't work if the legacy codebase is actively being worked on (eg bux fixes and new features and refactorings) or lacks test coverage and documentation. Starting from scratch also implies one major release where suddenly it's all Rust (so very risky). In contrast, we found that it's a much smoother transition for end-users and maintainers when we approach large codebases progressively, module by module, while the C engineers continue working on the C code and learn Rust in parallel. Of course, each migration is different but I wanted to clarify with our field experience. | ||||||||
| ▲ | elevation a day ago | parent | prev | next [-] | |||||||
> would require thousands of changes But LLMs are great at this, provided you have a test suite to keep the process on the rails. | ||||||||
| ||||||||
| ▲ | blastonico a day ago | parent | prev [-] | |||||||
> there's been a massive increase in people migrating from C to Rust due to LLMs. Strange. I was expecting the opposite move as LLMs know the C pitfalls and traps well enough to write corrected code. | ||||||||
| ||||||||