Toggle (pronounced to
The word “toggle” is also used informally to refer to a lottery. A lottery is a game of chance where numbers are drawn at random in order to determine the winner. Although many governments outlaw lotteries, others endorse them and regulate them to some extent. Similarly, in software development, many developers use a variety of techniques to conduct lotteries for feature selection. Many companies have a process for selecting features via lottery and a number of methodologies have been developed to manage this process, including Feature Toggles.
Generally speaking, it is best to avoid over-engineering a system by implementing large swaths of functionality as a series of complex toggles. Oftentimes, this leads to large code bases that are difficult to navigate and maintain. For this reason, it is recommended that teams try to keep the scope of their toggles small enough that they can easily test the configurations in production. To help with this, it is important to name feature toggles with descriptive names that make sense in the context of a team’s workflow.
This helps other teams to identify the purpose of the toggle and enables them to quickly determine how to configure it. In addition, it is a good practice to have a toggle configuration live side-by-side in source control. This allows the team to quickly see how a release performed in the past and recreate previous releases when necessary.
For a more dynamic approach, a team can choose to use a preprocessor’s #ifdef feature to hardcode a toggle. This method of management is less flexible than the commenting approach but can still allow for dynamic re-configuration. However, it is only suitable for situations where the team is willing to follow a pattern of deploying code in order to re-configure the toggle.
In most cases, a team should also be sure to test the toggle configuration they expect to see in production with all of its switches flipped On. This will allow them to understand the impact of a change before it goes live and can prevent surprise regressions down the line. Additionally, it is a good idea to test the fall-back configuration of any toggles they plan on flipping Off in the future as well.