Refactor existing code when you need to add features so there’s a space for the new features in the existing system before you add it.

Refactor Legacy Code

Makers and Menders

I’ve been getting back into some research interests of mine that require data acquisition from a variety of sensors so naturally, I’ve gravitated towards using the Raspberry Pi. If you’re unfamiliar with the Raspberry Pi, is a full-blown computer on a card about the size of a cigarette pack and offers a graphical user interface, …

Read More
Beyond Legacy Code: Nine Practices to Extend the Life (and Value) of Your Software

Summary of Seven Strategies Series

I finished my “Seven Strategies” series of 72 blog posts with seven strategies for implementing each of the nine practices from my book, Beyond Legacy Code: Nine Practices to Extend the Life (and Value) of Your Software. These posts are filled with practical advice for implementing the nine core practices from Scrum, Extreme Programming, and …

Read More
Refactor Legacy Code

Refactor to Learn What Not to Do

One of the things that I was not expecting when I started refactoring other people’s code was that I started to see improvements in the way I wrote my own code. I didn’t make those same mistakes. Refactoring other people’s code has taught me a great deal about things to do and things not to …

Read More
Refactor Legacy Code

Refactor to Clean Up Before Moving On

Of course, the best time to refactor code is while it’s fresh in your mind, right after having worked with it. Once I get a feature to work, I go back and think about how I can make the code easier to understand. I’ve done this so often that it’s natural for me, almost of …

Read More
Refactor Legacy Code

Refactor to Redesign When You Know More

One of the reasons that I’m such a proponent of doing emergent design or just-in-time design, is that this is how we learn a system and this is typically how a system needs to be built. It’s fallacious to believe that you can easily envision every aspect of a complex system and come up with …

Read More
Refactor Legacy Code

Refactor to Clean Up as You Go

We should be refactoring the code we write and all the code that we encounter all the time. Making little improvements to code should be just something that developers do without even thinking about it. I find that many of the anti-patterns the developers engage in when writing code are easy to spot and after …

Read More
Refactor Legacy Code

Refactor to Retrofit Tests in Legacy Code

The so-called safe refactorings are a subset of the refactorings from Martin Fowler’s book, Refactoring: Changing the Design of Existing Code. We call them safe because they require only straightforward changes to code that can be automated and proven to be correct with no unintentional side-effects. Safe refactorings are refactorings like Rename Method that lets …

Read More
Refactor Legacy Code

Refactor to Make Small Improvements

Another strategy to help you justify refactoring is to do it in order to make small improvements in an existing system. Don’t try to bite off the whole Apple at one time. Really bad legacy code got that way over long periods of time and in my experience, a similar, gradual approach can be good …

Read More
Refactor Legacy Code

Refactor to Learn an Existing System

One of the best opportunities to refactor code is when you’re starting to get to know it. This not only helps improve the code but it also improves your understanding of the code and helps everyone else who touches the code in the future. There are many kinds of refactorings that one can do to …

Read More
Refactor Legacy Code

Why Practice 9: Refactor Legacy Code

Having put the words “legacy code” in the title of my book, people often confuse my book with Michael Feathers’ book, Working Effectively with Legacy Code. On one hand, it’s great to be in such esteemed company. I love Michael’s book and I refer to it often. It’s full of great techniques for taming legacy …

Read More
Refactor Legacy Code

Rebuild or Refactor

Sometimes, when an important project is going poorly there’s a desire to start over. Sometimes this comes from management but often this comes from the developers themselves. They say if they only had a second chance and could start over then they can build the right system. But that almost never happens. Take it from …

Read More
Refactor Legacy Code

Code Transformations

A lot of poor designs can be attributed to sticking with an existing design as changing requirements show us the need for a better one. Oftentimes, an initial design is just a stab in the dark. We might not know enough to make an informed decision but we have to get something done, so we …

Read More
Refactor Legacy Code

The Stigma Around Refactoring

Refactoring is a critically important concept in software. Anyone involved in the software industry should understand exactly what refactoring is and why it’s valuable. Refactoring is not just the redesign of code. The redesign must behave exactly in the same way as it did before. In many situations, this also means bug-for-bug compatibility as well …

Read More
Refactor Legacy Code

Read, Write, and Refactor

A couple of years ago I got to realize a lifelong dream when I became a published author. I was surprised to learn that many of the skills that I gained in becoming a good software developer were actually useful to me in becoming a good writer. Like code, prose should be well-encapsulated and cohesive, …

Read More
Refactor Legacy Code

My Second Favorite Refactoring

In my last blog post, I shared with you my favorite refactoring and it might not have been what you were expecting. I can’t leave the topic without sharing with you my second favorite refactoring, as well. Like my favorite refactoring, my second favorite refactoring is also a safe refactoring, which means that if you …

Read More
Refactor Legacy Code

My Favorite Refactoring

Refactoring code is an essential activity when working with existing systems, as well as building new ones. Refactoring techniques allow us to safely transform code into designs that are perhaps better suited for future extension. The techniques used to refactor code range from very simple to quite complex and there is a strong emphasis to …

Read More
Refactor Legacy Code

Surgery on Legacy Code

One of my early blog posts that I wrote nearly 10 years ago that I called Sony Baloney discussed how the electronics giant cultivated some unusual, yet highly successful practices. One of the practices that Sony is known for is taking young and inexperienced engineers and putting them on new product development, while their senior …

Read More
Refactor Legacy Code

Don’t Be Scared to Touch Legacy Code

As Frank Herbert said in Dune, “Fear is the mind-killer.” He could have been talking about legacy code. As soon as we fear touching legacy code, we won’t do it. As a consultant, I know that merely giving my clients tools and techniques for working with legacy code isn’t enough, I also have to help …

Read More
Refactor Legacy Code

Seven Strategies for What to Refactor

Okay, you got the time and management approval to refactor some code. What do you do with it? Refactoring legacy code can be like unraveling a knotted rope and it can be hard to figure out where to start. Here are seven strategies for determining what to refactor. 1. Remove dead code Dead code is …

Read More
Refactor Legacy Code

Seven Strategies for When to Refactor

Given that there’s more code that could be refactored than our industry can handle, we have to decide what code should be refactored and what code doesn’t need it. If production software works fine and doesn’t need to be extended then there’s no need to refactor the code. Refactoring code is risky and expensive so …

Read More
Refactor Legacy Code

Seven Strategies for Helping You Justify Why to Refactor

Refactoring is improving the internal structure of code without changing its external behavior. Refactoring gives developers another chance to improve their designs and often gives management a cheaper and less risky way to ready an existing system for adding new features. Here are seven strategies to help you justify why to refactor code. 1. To …

Read More
Refactor Legacy Code

Avoid the Legacy Trap

Some of my clients put their best software developers on a project to build a system and then afterwards they put new hires on to maintain and extend it. Often the intention behind the original design is not clear to the people who have inherited the system and so they tend to make changes that …

Read More