Improve Legacy Code

Learn about improving the code and make things better as you go.

Our job would (seemingly) be a lot easier if we could simply take all the crappy old code floating around, trash it, and start over. But that’s not going to happen, so what do you do about it?

The typical bad legacy codebase may look something like this:

  • Functions span thousands of lines, with a near-infinite number of possible code paths.

  • Classes or modules have dependencies on twenty (or more) other classes.

  • A comment somewhere reads, “Don’t touch this, or everything will break!”

  • Another comment reads, “Ask Bob before changing this code,” where Bob is a programmer who left the company a decade ago.

And much more!

Sometimes when we need to fix a bug in code like this, the path of least resistance, just making the change without cleaning anything up, is the most prudent. However, consider the maxim, “If you find yourself in a hole, stop digging.” If we’ll need to maintain this code for a while, it’s best to make things better as you go.

Get hands-on with 1200+ tech skills courses.