Answer#
A working program already contains years of decisions, bug fixes and edge cases that nobody wrote down. A rewrite has to rediscover all of them. So the question is not "would Rust be better?" but "is there a problem that Rust solves and that cheaper changes do not?"
Use the checklist below. If you cannot fill in the first three lines with facts, you are not ready to decide.
- The problem, in one sentence, with evidence. For example: "the parser crashes on malformed files, and the bug tracker holds repeated memory-safety reports", or "the service needs more memory per instance than its limit allows", or "we must ship a library with no runtime to an embedded device". A feeling that the code is old is not a problem statement.
- The measurement that will show success. A crash count, a memory figure, a request latency, a binary size. Measure the old version now, on a workload you can repeat.
- Cheaper alternatives you have ruled out. Fix the hot function, add a cache, add tests and a fuzzer, upgrade the runtime, or wrap the old code (see the thread on rewriting or wrapping C code). Say why each does not solve the problem.
- How much of the code the problem lives in. Often it is one module. Port that module, not the whole program (see the thread on running old and new versions side by side).
- Test coverage of the old code. Without tests or recorded outputs, you cannot show that the port behaves the same. If coverage is poor, the first project is writing characterization tests, in the old language, which pays off even if you never port (see the thread on golden-file tests).
- Dependencies. List the libraries the code uses and check each has a Rust equivalent, or can be called through FFI. A missing library for a core job (for example a vendor SDK that only ships for one language) can decide the question alone.
- People. Who will review the Rust code, and who will be on call for it? Code that only one person can maintain moves a risk instead of removing it. Learning ownership and borrowing takes time that must be in the plan.
- The exit condition. What does "done" mean: the old code deleted, or both kept? A port that stops half-way leaves two codebases and an interface between them.
Common mistakes#
- Starting with the largest, most coupled module because it is "the core". Start with a module that has a clear boundary and good tests.
- Planning the whole port as one release. A port that ships module by module can be stopped, and it delivers value earlier.
- Treating the first working version as finished. It must be compared with the original on real inputs, not only on unit tests.
Related questions#
Is a rewrite ever clearly the right choice?#
When the old code cannot be fixed or wrapped, for example when its language runtime is no longer available for your target, or when most of the bugs you track come from one kind of memory error in code you must keep exposed to untrusted input. These are cases for a measured decision, not a general rule.
How long will a port take?#
The Ruststudio team has no honest number to offer without knowing the code. Port one small module end to end first and use that real effort to estimate the rest.
Sources#
- The Rustonomicon, "Foreign Function Interface" (for wrapping instead of rewriting): https://doc.rust-lang.org/nomicon/ffi.html