Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Refactored randomization module #24 #30

Merged
merged 1 commit into from
Mar 30, 2021
Merged

Refactored randomization module #24 #30

merged 1 commit into from
Mar 30, 2021

Conversation

jonathanmayer
Copy link
Contributor

No description provided.

@jonathanmayer jonathanmayer linked an issue Mar 30, 2021 that may be closed by this pull request

// Try to load the selected condition from the cache
if(conditionSet.name in conditionCache)
return conditionCache[conditionSet.name];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think always using braces is a better practice (someone always comes along and adds a condition without realizing) but let's do that with eslint and eslint --fix everything vs. bothering to do it here. I'll file an issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I mean it's not that terrible here because it's return or throwing below, but if someone comes along and inserts a new line before the return things fail in new and interesting ways)

throw "Conditions must have unique names."
conditionNames.add(condition.name);
}
let randomValue = Math.random();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went down the rabbit-hole of how Math.random works nowadays, I guess it's using https://en.wikipedia.org/wiki/Xoroshiro128%2B now, which sounds better than I remember!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about using the Web Crypto API for better randomness. I think we're OK with Math.random in this context, since the goal is just to divide users into a set of cohorts with target relative populations. Those cohorts will change (e.g., users withdrawing), and if researchers run statistical tests they'll have to account for cohort size.

@@ -53,3 +53,6 @@ export { linkExposure }

import * as socialMediaLinkSharing from "./socialMediaLinkSharing.js"
export { socialMediaLinkSharing }

import * as randomization from "./randomization.js"
export { randomization }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could do these as one line like: export { randomization } from './randomization.js? I haven't tried it yet but remember seeing it on MDN.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this. There's a pending proposal for namespace re-exports: https://github.com/tc39/proposal-export-ns-from

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, wasn't that merged in tc39/ecma262#1174 ? Although looking at the compatibility table on MDN we should probably avoid it for now anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I misunderstood the status of the proposal. Since we already need to use recent browser versions because of various WebExtensions APIs, I think we could switch to this syntax.

Copy link
Contributor

@rhelmer rhelmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it to you whether JS Math.random is high-quality enough for the needs here, my knowledge about Math.random was a little behind the times so that was interesting to learn about anyway.

@jonathanmayer jonathanmayer merged commit 484e73d into main Mar 30, 2021
@jonathanmayer jonathanmayer deleted the randomization branch March 30, 2021 02:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restore and refactor randomization module
2 participants