Skip to content

Enabling or disabling experiments

Josh Hiles edited this page Dec 23, 2023 · 1 revision

Sometimes you don't want an experiment to run. Say, disabling a new codepath for anyone who isn't staff. You can disable an experiment by setting a RunIf block. If this returns false, the experiment will merely return the control value. Otherwise, it defers to the global Scientist.Enabled method.

public decimal GetUserStatistic(IUser user)
{
    return Scientist.Science<decimal>("new-statistic-calculation", experiment =>
    {
        experiment.RunIf(() => user.IsTestSubject);

        experiment.Use(() => CalculateStatistic(user));
        experiment.Try(() => NewCalculateStatistic(user));
    });
}