5 ms·
Most people underestimate the value of refactoring existing code. Even a prototype provides a good base to start the refactoring. Of course it will help if the
by harikb 7y ago
Most people underestimate the value of refactoring existing code. Even a prototype provides a good base to start the refactoring. Of course it will help if the programming language helps with easy refactoring. In my projects, I expect to refactor the code at least 3 or 4 times before it reaches a state I am comfortable with.
IMHO, this is far better than starting from scratch. Both code and SQL are meant to refactored. Don’t over-engineer from the beginning adding usecases we know nothing about.
- capableweb 7y agoWell, you could also start from scratch multiple times and get better and faster each time, as you learn more things. And in the end you get a more fitting design for the final learnings.
- Ididntdothis 7y agoIf I had to rewrite something from scratch several times I would get very bored and the quality would probably go down. Better to refactor.
- usrusr 7y agoI like to refactor in the big and to rewrite in the small. In the big, the n-th rewrite will be just as constrained by how much we can keep in our head at the same time as the original attempt. Refactoring essentially means offloading to the computer what you already have in a computer-readable format. What an opportunity! What I mean with rewriting in the small is taking an existing logic-wart and, while trying to decipher it, taking notes in the form of a rewrite. After finishing the first approximation you take a long, skeptical look at both versions, "is that simple, elegant thing really doing the same?" and then you see the additional corner cases (and/or bugs, sometimes you'll never know) in a clarity that would be impossible to achieve just looking at the original code. It's mostly a reading tool. Sometimes I will trash the rewrite, but often the new version, with the non-obvious bits added will be far more readable than the original because it was written from the perspective of a reader with little knowledge of what the code should do, not by someone deeply immersed in the problem space.
- capableweb 7y agoYeah, if it's a boring problem I would probably get bored too, but I don't think the quality would go down. Naturally, repeating things makes you better each time. Refactor has it's place as well, it's basically rewriting smaller parts in different parts to transform something, you're writing those parts again and again when you continue to refactor for years.
- danielovichdk 7y agoAbsolutely agree. Refactoring is almost therapy. Clean up and fresh again
- jniedrauer 7y agoRefactoring production code can be very difficult. You often end up constrained by the existing code's public APIs, cross-API data structures, remote systems running the old code, etc. It's worth putting at least a little bit of thought into maintainability, even in the prototype stage.
- daxfohl 7y agoEspecially if it's a project with multiple people working on it. Refactoring will cause major merge problems for everyone doing anything else on those files. And if your team does best practices with code reviews and testing, then refactoring a chunk of code becomes a big project.