When Should You Refactor vs. Rewrite Your Code?

0
0
Asked By CleverCoder99 On

Hey everyone! I've been grappling with the decision on whether to refactor some existing code or to just rewrite certain parts from scratch. Each option has its benefits and drawbacks, and sometimes it's tough to figure out the best course of action for a project or team. I'm curious about what factors you all take into account when making this choice. Are there clear indicators that suggest refactoring won't cut it, or moment where rewriting might be overkill? I'd love to get your insights and any rules of thumb you use!

4 Answers

Answered By CodeWizard42 On

I always stick with refactoring over a complete rewrite. If the code works, just make it easier to work with through refactoring. Sometimes, I run into situations where a rewrite might make sense, like when I’m building something generic that’s really evolved after its initial version. But without a strong financial motive or necessity, I’d really avoid rewriting altogether.

TechieTommy -

Exactly! If it’s working, refactor to simplify things, but only consider rewriting if the current structure is fundamentally hindering what needs to be done.

Answered By CodingNinja88 On

For me, it's all about balance and timing. Minor refactors should happen naturally while you develop new features. But major rewrites? Those require solid justification because it's so easy to get lost in the revisions without seeing any benefits right away. Make sure you're well-equipped with tests before diving into a massive change.

Answered By BugHunter76 On

Honestly, I’ve found that if a piece of code makes you dread working on it, that’s a clear sign a rewrite might be necessary. If it’s working decently well but just looks ugly, refactor instead. Always go for the less drastic option unless there’s a solid reason to start fresh. And always, always have integration tests in place first!

Answered By RefactorMaster On

I usually say refactor until you feel it’s perfect. Keep making those small improvements alongside your regular coding. Full rewrites can be dangerous if you don't know what issues you'll hit along the way, so heavy refactoring is usually the safer bet.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.