We’ve all experienced this: you’re working on some code … probably code that was written a long time ago … and you realize that, with all the experience you’ve accumulated since the code was originally written, you could re-write (or refactor) the code so it would be much better.

The question is … how do you justify a refactoring of the code?

It’s been my experience that TPTB will rarely approve the effort involved in refactoring simply based on making the code base easier to work with, manage, and maintain. They want a concrete ROI for the change.

Refactoring provides many gives you the opportunity to enhance the code so it’s …

  1. More modern code.
  2. Easier to maintain.
  3. Easier to understand.
  4. Creates a standardized interface to the code.

… there are, however, many pitfalls …

  1. Takes a lot of time.
  2. Needs to be re-tested completely.
  3. Risks breaking other code that interacts with the original in unknown ways.

I’ve worked on a number of projects recently where the code base would have benefited greatly from refactoring. And, we had every intention of doing some level of refactoring, but in the end we had to settle with just writing an adapter procedure to the existing code as there just wasn’t enough time in the plan to fully refactor.

Our wrapper could have great promise to be a primary entry point to well written, highly structured, easily interfaced, code … but I doubt it will ever come to pass.

So the question is still there … how do you go about justifying a code rewrite?

About David:
David is a Principal Software Engineer for PTC, Integrity Business Unit. He cut his teeth on the S/36 and has more than 25 years of experience on the IBM i / System i / iSeries / AS400. He primarily works in Java and ILE RPG specializing in cross platform integrations. David has received the COMMON Distinguished Service award and was named an IBM Power Systems Champion. David is an active volunteer with the American Diabetes Association's Tour de Cure fundraising bike ride. He is currently captain of Team RED Chicago. David runs and maintains midrange.com. His personal blog is Geeky Ramblings.