We use function flags to enable / disable some functions in our system.
I had a discussion with my colleague about the standard way to add function flags to the code itself:
Consider the following method:
def featured_method do_this do_that end
The method is called from about 15 different places inside our code.
You would recommend adding a check to see if the function is enabled before each call to this method:
if feature_enabled?(:feature_key) featured_method end
Or inside the featured_method element itself, for example:
def featured_method if feature_enabled?(:feature_key) do_this do_that end end
The advantage of having a condition inside the method itself is obvious: the DRY code and the fact that when you want to constantly add a function, you simply remove the condition from the method.
The advantage of having a condition over each call is that it is very clear whether this method is executed or not without going into the featured_method code itself, which can save a lot of headaches.
I was wondering if there is another solution or standard for such problems.
source share