4 ms·
There's also the many cases where the code is an actual mess because it had unclear requirements during its whole development, or it was written by someone who
by phito 2y ago
There's also the many cases where the code is an actual mess because it had unclear requirements during its whole development, or it was written by someone who doesn't fully grasp the language they're using.
I've rewritten several of such projects, successfully reduced complexity and improved performances just by knowing what I am doing.
- magicalhippo 2y ago> knowing what I am doing This code is a mess, I don't understand what it's doing is very different from I get what it's doing but this code is a mess. The first should probably be a strong sign you should not start rewriting the code, while the second can be a decent position to consider rewriting it.
- MereInterest 2y agoI think I’d distinguish between rewrites and refactors. A rewrite starts from a blank slate, where a refactor starts from the previous version. Being unable to understand the code in its entirety does not mean that somebody is unable to understand pieces of the code. Refactoring those pieces into easier-to-understand portions can be done, even when the end-to-end flow is still being contemplated.
- magicalhippo 2y ago> Refactoring those pieces into easier-to-understand portions can be done Right, but the main point still stands I think, that if you don't understand the full code, you run a risk at introducing bugs when refactoring portions of it. Code that seemingly does nothing might in fact do something due to non-local effects, ie global variables in disguise, and other pitfalls. A "favorite" is using reflection to modify some non-local variable rather than accessing it directly, making it very difficult to find during code searches. Sometimes these bugs can be glaring, other times they can be more subtle and only be detected once they've inflicted significant damage to customer data.
- wrsh07 2y agoOne of the challenges with proposing the rewrite of a complex codebase is that it requires the person planning and executing the rewrite to understand the requirements and the source of complexity. I used to think that there existed some queries that would benefit just from being rewritten from first principles. And then someone rewrote them incredibly naively. That is no better than the original!