ruby - Feature flags best practice: condition inside or outside of a method? -


we're using feature flags in order enable/disable features in our system.

i had discussion colleague on what's standard way of adding feature flags code itself:

consider following method:

def featured_method   do_this   do_that end 

the method being called 15 different places inside our code.

would recommend adding check if feature enabled before every call method:

if feature_enabled?(:feature_key)   featured_method end 

or inside featured_method itself, this:

def featured_method   if feature_enabled?(:feature_key)     do_this     do_that   end end 

the advantage of having condition inside method obvious: drying code, , fact when want add feature permanently, remove condition within method.

the advantage of having condition before every call is clear whether method gets executed or not without going featured_method code itself, can save quite lot of headaches.

i wondering if there's solution or standard kind of issues.

i merge both approaches.

this lead dry code on callers side. not violate srp in feature_method , communicate going on - if can find better name me:

def may_execute_featured_method   featured_method if feature_enabled?(:feature_key) end  def featured_method   do_this   do_that end 

the caller use may_execute_featured_method


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -