Alexandru Bolboaca

CTO at Mozaic Works


Surgical Refactoring of Non-Tested Code – A Worked Example
Friday 16:05 - 16:50
legacy code

Your rating:

Most programmers don't work on greenfield codebases. Most likely, you work on codebases that have been around for a few years at least, 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. The examples are in C++, but I will explain how to adapt this technique to your programming language.

Check the slides


Alex is a polyglot programmer, trainer and coach at Mozaic Works. He has worked for almost 20 years in software development, for various industries and in various European countries and UK. He has been involved in large projects in many industries, including banking, energy, telecommunications, media planning, printing, pharma, eHealth. From practical experience, he also advises and teaches on topics such as architecting microservices, agile architecture, usable software design, evolutionary design, crafting code, clean code and refactoring legacy code with focus on design. Alex co-facilitated the first code retreat outside US in Bucharest in 2009. Since then, he’s facilitated tens of events such as coding dojos, architectural katas, code retreats and others in many countries from Europe. He is also a contributor to publications and blogs such as: Today Software Magazine, Agile Record Magazine, Mozaic Works Blog and his own blog. Recently, he has authored his 3rd book, “Hands-on Functional Programming in C++”.