Header Image

Surgical Refactoring of Non-Tested Code – A Worked Example

As a C++ programmer, chances are that you are not working on greenfield codebases. Most likely, you work on codebases that have been around for more than 5 years, and some of the developers have already left the team or the organization. Perhaps you have some documentation, and most likely it is not up to date.

However, you need to change some of the existing code to fix issues, to add features, or to refactor. If you are lucky, you have tests that you trust. I would bet though that many of the lines of code that you need to change are not covered by automated tests. You may even be afraid to change them, since they are not clear enough and you may introduce more issues.

There are a few answers to this conundrum, but none of them are quite satisfactory. What would be ideal is to have a technique that you can learn quickly, and that you can apply to make surgical refactoring on non-tested code in a relatively short time.

In this session, I will show a worked example of applying such a technique. I’ve presented it in the past as “refactoring through pure functions”, but this time we will look at one actual example that you can hopefully use for similar code patterns. I will take a small codebase, and use the following technique to refactor and add tests:

  • Step 1: refactor to pure functions
  • Step 2: write data-driven or property-based tests on the pure functions
  • Step 3: refactor the pure functions into an improved design, with test coverage

At the end of the session we will have time to discuss and open to your questions related to the technique, and where you can learn more about it.

February 23 @ 11:45
11:45 — 12:30 (45′)

Online

Alex Bolboaca

Register Now

× How can I help you?