Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evolution or Revolution to fix poorly written code

Tags:

refactoring

I've done some work for a personal project of mine, and now I understand why people tell us to plan out all our interfaces and design before coding. I've got some good classes and already have some working code, but all in all the the organization (architecture) is somewhat of a mess, and I'm already saying "If I did it again, I would do it like this...". The question is, should I sketch out a plan of how I want my code to look, and refactor the existing code to the new model, or if I should take what works great, and write all new code for the deficient parts (basically starting from scratch with a fair amount of copy and paste from this project).

I've got git history I'm not sure I want to lose, but the task of slowly rewriting everything seems daunting. So the question I'm asking is: when refactoring a young project, should one use evolution or revolution to get it right the second time?

like image 681
MighMoS Avatar asked Feb 17 '09 20:02

MighMoS


1 Answers

Refactor the old code (evolution). Rewriting code always introduces problems that you didn't think of. I am sure there have been updates to the existing code, and a lot of those updates are bug fixes enhancements etc. You may not know why you made a change at the time, but you needed to, and rewriting the code could remove that needed change.

Taking small steps also helps you avoid the "Oh 'expletive'" scenario where you try and make some massive change and encounter a situation where it doesn't behave they way you expect it to. With evolution, you can back out a change and still have a working system since the architecture is somewhat finalized.

like image 154
kemiller2002 Avatar answered Oct 03 '22 22:10

kemiller2002