facebookarchive / planout

PlanOut is a library and interpreter for designing online experiments.
http://facebook.github.io/planout
Other
1.68k stars 216 forks source link

(Minor) Not obvious how to check for list membership #113

Open omnilinguist opened 8 years ago

omnilinguist commented 8 years ago

After looking at the language reference and the compiler (https://github.com/facebook/planout/blob/master/planout-editor/js/utils/planout_compiler.js), the way to check for existence of something in a list is not well documented.

One use case I can think of is in case I want to implement whitelists and/or custom targeting. This is a completely fabricated example (though intended to mimic real world use cases), but let's say I want to show a treatment only to users in certain countries, and I am able to pass the country in as an argument. Here is a workaround that worked when quickly playing with the PlanOut editor:

whitelist = @{'US': 1, 'UK': 1};
if (whitelist[country] != null) {
  result = "a";
} else {
  result = uniformChoice(choices=['b', 'c', 'd'], unit=country);
}

Basically, I just create a dictionary containing (as keys) the values I want to whitelist and set their (dictionary) values to any (non-null) value. This seems like it works, and is probably more performant than having to iterate through a list to check for existence of an element, especially if the list is very long. One could argue that this benefit outweighs the awkwardness of having to use a dictionary with dummy values just to check for simple existence, but seems like a relatively minor issue.

If this seems reasonable to recommend as an approach for this situation, I could make a pull request to update the documentation at some point. Or, does anyone have better ideas in mind?

bric3 commented 6 years ago

@omnilinguist I agree that Planout DSL is missing a few things in that regard

For beta-testers I was able to avoid the if/else using the dictionary directly :

beta_users = @{ '1242354':'beta', 'qwqewwe':'beta', '00t634986':'beta' };
is_beta = beta_users[user_guid];

But this can be a bit tedious to type, but more importantly it is error prone.