-
Notifications
You must be signed in to change notification settings - Fork 208
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
style(governance): lint for Jessie dialect (WIP) #3876
Conversation
@@ -106,7 +107,7 @@ const makeBinaryVoteCounter = (questionSpec, threshold, instance) => { | |||
if (choice < 0) { | |||
spoiled += shares; | |||
} else { | |||
tally[choice] += shares; | |||
tally[+choice] += shares; |
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.
What does a unary plus do as an array index? Is it coercing choice
to a number?
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.
Yes, I think so.
I have only a vague understanding of why, but...
Jessie omits mutation through computed property names. Jessie has syntax for mutating only number-named properties, which include integers, floating point, NaN, Infinity, and -Infinity.
-- https://github.com/endojs/Jessie
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.
We want to make it easier to statically reason more reliably about Jessie programs, while avoiding undue syntactic burden. A typing practice common outside JS and approximated by TS is that records are heterogeneously typed -- each named field is separately typed, and arrays are uniformly typed. But JS fights us here, by making array indexes just be normal property names, and generalizing the []
syntax to apply to all property names. Computed indexing destroys simple static reasoning about heterogeneously typed record fields.
The more correct syntax for Jessie to insist on to ensure computed property names are array indexes would be obj[index|0]
as done in asm.js. Perhaps we should do that instead. But we opted for a looser compromise to get a slightly less unpleasant syntax. Our looser compromise depends on normal records not having properties named for floating point values or NaN
or Infinity
or -Infinity
.
(Btw, I think the obj[+index]
syntactic compromise is originally due to @mikesamuel . Thanks!)
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.
The
E(paramMgr)[`update${paramName}`]
below is a great example of something that is prohibited by Jessie, but is in this case a good idea. For this one, I think the correct approach is an appropriate eslint-ignore-like comment or ts-ignore-like comment, though I don't yet know how to do those for Jessie. It is the right approach because it is unusual for code like this to be a good idea, and its costs to static reasoning are real and significant. As with ts-ignore comments, the Jessie ignore comment should be accompanied by rationale.
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.
For the sort of formal methods I hope to use, I don't expect them to cope well with ignore
comments.
I'm inclined to extract the computed property lookup stuff to a function in a separate file, which we would reason about separately.
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.
Yes. Along the lines of your fromEntries
suggestion at #3876 (comment) , for each of these accesses, there is already adequate reflective API. For property reading by itself, for example, there is
Reflect.get(tally, choice)
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.
I had the opposite opinion earlier, but now I don't see many gains from E(paramMgr)[`update${paramName}`]
. What makes this a good idea?
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.
The earlier answer was:
each updateFoo() message is a separable capability.
I mentioned "my preference for static typing", which argues for your E(paramMgr).update(paramName, proposedValue)
suggestion; it looks like Jessie suggests a similar preference.
I suppose the separate capability could always be expressed using currying: proposedValue => E(paramMgr).update("knob1", proposedValue)
.
I can see it both ways.
Oh... the But |
Objects-as-maps is the antipattern we're trying to avoid. Just use Map if possible. If it's impossible, then unfortunately you're out of luck.
Please just
|
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.
Wonderful to see! We need everyone to do a lot more of this! Thanks for getting us started!
@@ -106,7 +107,7 @@ const makeBinaryVoteCounter = (questionSpec, threshold, instance) => { | |||
if (choice < 0) { | |||
spoiled += shares; | |||
} else { | |||
tally[choice] += shares; | |||
tally[+choice] += shares; |
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.
We want to make it easier to statically reason more reliably about Jessie programs, while avoiding undue syntactic burden. A typing practice common outside JS and approximated by TS is that records are heterogeneously typed -- each named field is separately typed, and arrays are uniformly typed. But JS fights us here, by making array indexes just be normal property names, and generalizing the []
syntax to apply to all property names. Computed indexing destroys simple static reasoning about heterogeneously typed record fields.
The more correct syntax for Jessie to insist on to ensure computed property names are array indexes would be obj[index|0]
as done in asm.js. Perhaps we should do that instead. But we opted for a looser compromise to get a slightly less unpleasant syntax. Our looser compromise depends on normal records not having properties named for floating point values or NaN
or Infinity
or -Infinity
.
(Btw, I think the obj[+index]
syntactic compromise is originally due to @mikesamuel . Thanks!)
@@ -106,7 +107,7 @@ const makeBinaryVoteCounter = (questionSpec, threshold, instance) => { | |||
if (choice < 0) { | |||
spoiled += shares; | |||
} else { | |||
tally[choice] += shares; | |||
tally[+choice] += shares; |
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.
The
E(paramMgr)[`update${paramName}`]
below is a great example of something that is prohibited by Jessie, but is in this case a good idea. For this one, I think the correct approach is an appropriate eslint-ignore-like comment or ts-ignore-like comment, though I don't yet know how to do those for Jessie. It is the right approach because it is unusual for code like this to be a good idea, and its costs to static reasoning are real and significant. As with ts-ignore comments, the Jessie ignore comment should be accompanied by rationale.
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 cool to see! I added comments separately.
One question for @dckc, what's the benefit of export const makeWeakMap = () => new WeakMap();
? Maybe I don't understand the reasoning behind wanting to reduce usage of new
The stated justification is not all that clear to me either:
I guess there's a hazard of calling functions as constructors when they weren't meant to be? I'm fuzzy on what that hazzard is @erights maybe you want to beef up the justification a bit? Add a link to some popular explanation of this hazard? also...
Jessie doesn't have |
97f1d53
to
6ce7f17
Compare
@mhofman had a suggestion in the area of types for parameterized governance:
|
The code is remarkably close to Jessie. Remaining issues include: - new WeakMap() - dynamic property names in paramManager
72b8586
to
ed2253f
Compare
thanks landing a bunch of |
I got surprisingly few lint errors when I added
@jessie-check
to the governance sources. The code is already remarkably close to Jessie. The biggest issue I see is:For code such as...
Is that just irreconcilable with Jessie? Or is there some
Object.defineProperty(...)
idiom that we prefer in such cases?The other issue is relatively minor:
new
innew WeakMap()
(1 occurrence)I'd be tempted to put
in the same directory, named
tablemaker.js
orjessielib.js
or some such and import from there. I lean against adding a new package dependency for a 1-liner (plus, I'm not sure how stable our jessie stdlib package is).