The before code always applies a discount, which may not be ready. The after code checks a feature toggle before applying the discount, allowing dynamic control without redeployment.
### Before (no feature toggle)
def process_payment(user, amount):
# New feature: apply discount
discounted_amount = amount * 0.9
charge_user(user, discounted_amount)
### After (with feature toggle)
FEATURE_TOGGLES = {
"discount_feature": False
}
def is_feature_enabled(feature_name):
return FEATURE_TOGGLES.get(feature_name, False)
def process_payment(user, amount):
if is_feature_enabled("discount_feature"):
amount = amount * 0.9
charge_user(user, amount)