We're using feature flags in order to enable/disable certain features in our system.
I had a discussion with my colleague over what's the standard way of adding feature flags to the code itself:
Consider the following method:
def featured_method
do_this
do_that
end
The method is being called from about 15 different places inside our code.
Would you recommend adding the check if the feature is enabled before every call to this method:
if feature_enabled?(:feature_key)
featured_method
end
Or inside the featured_method itself, like this:
def featured_method
if feature_enabled?(:feature_key)
do_this
do_that
end
end
The advantage of having the condition inside the method itself is obvious: DRYing up the code, and the fact that when you want to add the feature permanently, you simply remove the condition from within the method.
The advantage of having the condition before every call is that it is very clear whether that method gets executed or not without going into the featured_method
code itself, which can save quite a lot of headaches.
I was wondering if there's another solution or a standard for those kind of issues.