How to not rewrite it in Rust
This article is wonderful and I hope as a setup for second article, &quot;How to Rewrite it in Rust&quot;!<p>&gt; However at best, the temptation to RiiR is unproductive<p>&gt; A much better alternative is to reuse the original library and just publish a safe interface to it.<p>Just as models are a lower dimensional representation of a more complex problem, [1] I have to re-iterate that there are no truth(ism)s in software and as in all engineering, there are trade offs. RiiR can and often is a valid choice. The author talks about &quot;introducing bugs&quot;, under an engineering approach to a rewrite, more like a language-port, rewrites can _find_ a lot of bugs. One such way is as follows.<p>1. keep the same interface in the new system, client code should work against either system.<p>2. have a body of integration tests, capture these from the field OR write a small collection of orthogonal tests, somewhere between unit and integration.<p>3. use the tooling, bindgen, etc and generate as much of the interface programmatically as possible.<p>4. iterate on the port, doing differential testing against both systems.<p>Doing a language port is comparable in work to long term maintenance and refactoring of an existing codebase. As the tooling gets better, RiiR will be more of a smooth oxidization.<p>If you own the C&#x2F;C++ that could possibly get rewritten, I&#x27;d think one needs to rationalize NOT RiiR. Better tooling (IDE, build), perf tooling is improving, low bug count, increased team velocity, build is improved, etc.<p>But the biggest reason to RiiR is safety. Integrating a body of C&#x2F;C++ code into your rust codebase introduces a huge amount of unsafe code, much worse than surrounding your entire rust program with unsafe { }.<p>At least do what is outlined in the article but ALSO compile the native code into Wasm and run it from within a sandbox.<p><i></i>edit, something like a library for reading (parsing) a file format, should absolutely be RiiR or run from a sandbox. Data parsing and memory corruption vulnerabilities are excellent dance partners.<p>[1] see PCA <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Principal_component_analysis" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Principal_component_analysis</a>