Hacker News new | ask | show | jobs
by jupp0r 3689 days ago
If you do feature flags by inserting if blocks throughout your code you will create tech debt anyways. The goal is to have one if block and hide the changed behavior behind interfaces (or polymorphic functions if you are using functional languages). Dependency injection is your friend.

If you don't do this, you won't scale beyond a hand full of feature flags. Chrome has hundreds, for example.

2 comments

Can you expand on this? I'm interested to see how this works in a real code base.

I'm thinking something like an initial (maybe massive) if block in the setup of the application that sets all of the behavior/features by declaring which implementations get set to which interfaces? After this if block, all of the DI stuff is set?

This of course means you need to use a DI framework of some sort.

Using feature flags is something I'm investigating because our current model is a git branch for every feature, and I wonder/fear it only works because we're a small team that has worked together for a while and in the future when we grow this will break down.

I was about to say the same thing as your parent. I recently had a nice feature toggle experience using a strategy pattern with DI.

Basically there was one 'if' statement in the DI container configuration code that looked up a config. Basically

if (newPricingStrategy) bind IPricingStrategy to NewPricingStrategyImplementation else bind IPricingStrategy to OldPricingStrategyImplementation

In the case of Chrome are they feature flags or configuration flags?