Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Feature Toggles

Feature Toggles

When you develop in a fast cycle and want to continuously deploy or when you have a project with lots of customer specific configurations feature toggles are a must and you probably use the simplest one `if () then {}`. When you switch between features in your code you will accumulate technical debt fast and if you don't watch out it will turn into a monster. I will show you how to tame the beast that is feature toggling by showing good practices to introduce more complex toggle conditions, how to separate new and old behaviour and how to easily get rid of them when you don't need them.

Denis Brumann

May 12, 2017
Tweet

More Decks by Denis Brumann

Other Decks in Programming

Transcript

  1. Feature Toggles
    Denis Brumann

    [email protected]
    Twitter: @dbrumann
    phpday 2017
    Slides: https://speakerdeck.com/dbrumann/feature-toggles
    Code: https://github.com/dbrumann/toggle-demo

    View full-size slide

  2. public function hasValidShopLocation()
    {
    $location = $this->getLocation();
    return (
    $location->isValid()
    && (get_class($location) !== CityLocation::class)
    && !($location instanceof NullLocation)
    && !($location instanceof VendorCustomLocation)
    && !(
    $location instanceof GpsLocation
    && $this->locationFeatureHandler->gpsLocationNeedToHaveStreetToBeValid()
    && $location->getStreet() === null
    )
    );
    }

    View full-size slide

  3. Look back
    Did we need toggling in previous features?

    How did we solve them?
    Plan ahead
    Do we need to toggle this in dev/qa/production?

    How long will this toggle stay in our code?

    View full-size slide

  4. Question existing toggles
    Do complex conditions make the code hard to read?

    Do we often have to change the context for the toggle?

    View full-size slide

  5. Remove toggles
    Even better: avoid writing them in the first place

    View full-size slide

  6. Thank You
    https://joind.in/talk/18529

    View full-size slide