@bagder
> I don’t believe in rewrites into any language. I believe in constant and never-ending polishing, iterating and refactoring.
I always had this tension between rewriting vs changing when working on an old codebase, even when everything was in my favourite language already (I worked on the XAPI project for 9 years)
What worked well:
* Refactor accumulated cruft: can it be done more simply, or in a more general way? (I like deleting code more than adding it)
* Try to understand *why* the code is like that even if it makes no sense, or looks completely buggy. "Chesterton's fence" principle. (maybe the code is correct, but for a use case you haven't even thought of, because it is not as relevant today as it was 10 years ago)
* Replace hand rolled code entirely with an upstream project that is better maintained for a specialized area (sometimes requires a small wrapper, and differential testing). Careful that the replacement is actually better.
* Use new language features that simplify code, detect more bugs, etc. I was able to once delete an entire module, because it was implementable in one line using the standard library now
* Drop support for features or configurations that noone used
Having said that, sometimes rewriting small modules to incorporate all the design evolution, and lessons learned *is* worthwhile: design a new module from scratch with a new internal API (not a drop-in, that limits the design space).
Have a clear goal (more robust, better performance, etc.)
Then gradually move callers that used the old module to use the new module and new API. Everything keeps working and building during this time. If something goes wrong it is also easier to find where rather than doing one big change.
At the end you have your (module) rewrite.