-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
choice randomization: better approximation of JR behaviour, fixes #49 #241
base: main
Are you sure you want to change the base?
choice randomization: better approximation of JR behaviour, fixes #49 #241
Conversation
🦋 Changeset detectedLatest commit: 954f9e9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
69be0c6
to
6432f97
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. I really appreciate how the commentary here tells the why story!
As discussed a bit in Slack, I think a couple of adjustments would make the change clearer. And would either make the need for some of the commentary moot, or make the remaining commentary more useful.
-
There's a clear "JavaRosa compatibility" responsibility here. While it is inherently coupled to the
seededRandomize
implementation, it is also very specifically a mapping to a more general concept:longValue
. I think it would help immensely for future understanding of what's going on here if we make that an explicit function, with the same name. -
In general, I've found liberal use of JSDoc comments (i.e.
/** ... */
) really helpful. The comment style provides support for all sorts of editor functionality.Here, we'd get a lot of benefit from inline linking support (i.e.
{@link $URL_OR_REFERENCE}
and/or{@link $URL_OR_REFERENCER | more specific title}
). In particular I think a permalink to the JavaRosaresolveRandomSeed
method would be useful, and probably also links to the pertinent issues. This ties directly to point 1: giving the JavaRosa-compatible thing a name corresponding to the Java thing it emulates, also gives a clear place for that JSDoc to reference it and clarify the nuances it's addressing.I think a few tweaks to this comment would be pretty much perfect.
-
We can eliminate the divergences from JavaRosa by using BigInt values for several of these cases. This, combined with their usage in a clearly articulated
longValue
JR-equivalent would also eliminate the need for commentary on those cases. In my local exploration of this, what I found made the most sense with the least fuss was to changetype Int = number
totype Int = bigint | number
, then have thelongValue
equivalent also produce thatInt
type. Pretty much everything else that would need to change falls out of that (i.e. any mixed-type operators producing fractional values do the appropriate explicitNumber()
casts to preserve those mathematical semantics).It'd also be useful for the
Infinity
/-Infinity
cases to be bound to constants with clear names. Insofar as there's still benefit to commentary on those, JSDoc on those constants is a good place.
Aside from making some of the intent clearer here, I suspect we may find there are other edge cases where we want to cordon off JavaRosa-compat/Java-isms in a general and reusable way. Even if that seems like a premature abstraction, doing it in this case is a direct, 1:1 linkable reference to the existing abstraction we'll be emulating.
Edit: oh, and this definitely feels like it deserves a changeset.
This needs updates for:
Drafting! |
706f380
to
159f06c
Compare
c435390
to
b7cce27
Compare
5fa9d75
to
9bb403c
Compare
9bb403c
to
c83fef2
Compare
Done! |
Closes #49
I have verified this PR works in these browsers (latest versions):
Some related problems remain to be solved:
This brings what Webforms does more in line (barring #240) with what Javarosa does, and as such fixes the immediate problem of #49.
I felt it was worth it to be verbose with the comments here, so check those out.
This story is not over yet. Depending on whether we deem it OK to change the seed derivation algo, I'd like to make it value type/length agnostic and would just hash the input in its textual form and derive a seed from that hash - see getodk/javarosa#800. And in that case this code will need to be altered again.