How do you deal with a bad legacy code?

How do you deal with a bad legacy code?

Whether you’re just getting started — or you’ve been working on it for a while — here are eight tips that you should follow.

  1. Test the Code.
  2. Review Documentation.
  3. Only Rewrite Code When It’s Necessary.
  4. Try Refactoring Instead.
  5. Make Changes in Different Review Cycles.
  6. Collaborate With Other Developers.
  7. Keep New Code Clean.

Why is legacy code so bad?

Legacy code vs. bad code It’s a phrase that often gets used when a programmer joins a project and they don’t like the existing codebase. “The reason that [programmers] think the old code is a mess is because of a cardinal, fundamental law of programming: It’s harder to read code than to write it.”

Is it a chore to work with legacy code?

Legacy code involves dealing with older code and code you didn’t write can be a chore. But, unless you’re starting a project from scratch, it’s inevitable. And that means you need a better way to work with legacy code.

Why are so many developers afraid of legacy code?

Wading into legacy code can feel like walking blindly into a minefield. Some developers are too afraid to touch it, and then you’re stuck unable to implement new features altogether. Fear is your worst enemy in facing legacy code. But you shouldn’t cannonball into it, either.

What’s the best way to clean up legacy code?

One way to do this is by using a code quality tool, like a static code analysis tool. You can set a baseline and then run an analysis on the new code to make sure it’s clean. And you can suppress results from your codebase. Helix QAC and Klocwork, for example, make this very easy to do.

What’s the best way to refactor legacy code?

Refactor code that has unit tests — so you know what you have. Start with the deepest point of your code — it will be easiest to refactor. Test after refactoring — to make sure you didn’t break anything. Have a safety net — e.g., Continuous Integration — so you can revert to a previous build. 5. Make Changes in Different Review Cycles