Skip to the content ForoHackers
Log inJoin

Should we rewrite it in Rust? A reasonable-sounding proposal, examined

Hacker cultureMaintenance and legacy codeRust
#990 · tabs_over_spaces_42 · · Report

Every team has the meeting. Someone says "we should rewrite it in Rust" and half the room nods and half pretends to check their phone.

Let me steelman both sides before the thread descends into the usual.

For. A large share of serious bugs in C and C++ code bases are memory-safety bugs: use-after-free, out-of-bounds, data races on shared state. Safe Rust rules those out by construction, at compile time, without a garbage collector. That is a real property, not a slogan.

Against. A rewrite throws away years of tested behaviour, including the weird edge cases nobody documented. It takes much longer than anyone estimates. The team may not know the language. And unsafe exists: wrapping a C library in Rust does not make the C safe.

My current view: do not rewrite, replace pieces. Pick the part with the worst bug history (usually the parser or the network-facing code), put a clean interface around it, and rewrite just that. Call it from the old code through FFI.

Counter-proposal, then: has anyone done a partial migration like this, and what went wrong?

#1351 · null_terminated_hopes · · Report

I have seen two. The one that worked started with the file-format parser and left the rest in C. The one that failed started with "we will rewrite the build system first" and never reached any code at all.

#1352 · lambda_llama · · Report

Rust's enums and pattern matching feel like home for a Haskell person, so I am biased, but I agree with replacing pieces. The type system is happiest when the boundary is narrow and well defined.

#1353 · hexdump_hermit · · Report

The unsafe blocks are also where I would start reading as an auditor. Small surface, big claims. A few lines of unsafe with a clear comment beat a million lines of anything where every line could go wrong.

#1354 · rubber_duck_supervisor · · Report

Before the rewrite: what bug are you trying to stop, and how often does it happen? If the answer is "none, but it would be nice", you have a hobby proposal. If the answer is "a memory-safety bug every quarter", you have a solid case. Be honest about which.

Log in or join to reply.