6

How to refactor a rapidly evolving code?

 2 years ago
source link: https://www.codesd.com/item/how-to-refactor-a-rapidly-evolving-code.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to refactor a rapidly evolving code?

advertisements

I have some research code that's a real rat's nest, with code duplication everywhere, and clearly needs to be refactored. However, the code base is evolving as I come up with new variations on the theme and fit them into the codebase. The reason I've put off refactoring so long is because I feel like the minute I spend a few days coming up with good abstractions, seeing what design patterns fit where, etc., I'll want to try out some new unforeseen idea that makes my abstractions completely inadequate. In other words, because of the rate at which the code is evolving, I really have no idea where abstraction lines belong, even though there is no shortage of (approximate) duplication and the general messiness of the code makes adding stuff to it a real pain. What are some general best practices for coping with this kind of situation?


Don't spend so long refactoring!

When you're about make a change in a piece of code, consider refactoring it to make the change easier.

After making the change, refactor again to clean up the damage done by that change.

In both cases, make the refactorings small and do them quickly, and move on.

You don't have to keep your code pristine at all times, but remember that it's easier to go fast if you have well-factored code to work in (and if you have good unit tests, of course).


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK