Maintaining flag hygiene

For this tutorial, flag cleanup has been quick and simple. There are only a couple of flags in the project and we're certain about whether they're needed or not. However, engineering teams who make heavy use of flags find that it can take more effort to manage the technical debt raised by old flags.

Here are some of the techniques that we've seen for maintaining flag hygiene in large codebases.

Regular clean-up sessions

Some teams schedule a "Flag Cleanup Day" every few months. In preparation, a team member produces a list of flags to be cleaned up. The list is divided up amongst the team. Then, each team member goes through their assigned flags and, for each flag, produces a patch or pull request which removes the flag from the code.

There are problems with this approach. Most obviously, it requires that the entire team stop work on vital projects and change their work context to become code janitors.

Change the "Definition of Done"

A better way to manage technical debt is to standardise the practice of paying off small amounts at the appropriate times. When a feature is fully rolled out, or an experiment is ended, that's the best time to clean up the flag. So, when scheduling the work for rolling out a feature, include the flag cleanup work in the schedule.

This is known as changing the "Definition of Done". The feature rollout is not considered "done" until the cleanup is finished.

Prep a pull request

Cleanup goes faster if the work to change the code has already been done. When creating a pull request to add a flag into the code, you can also create a second pull request which removes the flag. This pull request should simply remove the flag code without other changes; this minimises the number of conflicts to resolve even if - as often happens - the code for the new feature is updated before the rollout is finished.