-
Notifications
You must be signed in to change notification settings - Fork 177
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
[P1-N09] Only return named variables #1229
Conversation
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
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.
Looks great
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.
Looks great! A few small nits.
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
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.
Looks great. One minor comment.
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
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.
LGTM!
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
@@ -15,17 +15,17 @@ contract("ResultComputation", function(accounts) { | |||
await resultComputation.wrapAddVote(priceOne, web3.utils.toWei("5")); | |||
// Frequency table: priceOne->5. Cutoff: 2.5. | |||
let resolved = await resultComputation.wrapGetResolvedPrice(minVoteThreshold); | |||
assert.isTrue(resolved.isResolved); | |||
assert.equal(resolved.price, priceOne); | |||
assert.isTrue(resolved[0]); |
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.
@mrice32, @nicholaspai and @ptare if we make this change we can't directly refer to variables if the function called returns more than one variable. I'd like to get your input before making this change. Options are:
- revert to returning named variables. This would mean that we are inconsistent. might be acceptable iff the function returns two separate variables. rule is then that if it has two we use named variables.
- accept the small hit in code readability and ensure to always add comments for code readability.
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.
After talking to @mrice32 and @nicholaspai about this we converged on two different opinions between readability and consistency. @mrice32's preference is readability and @nicholaspai's preference is consistency.
While it's inconsistent to have named return types in some functions and not others, I feel the benefit in integrating with the contracts with simple named values outways the inconsistency cost. In all other cases having a named return variable is the desired pattern.
Going forward as a styling rule we will now always used named return variables in all cases EXCEPT when returning multiple variables from a Solidity function.
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.
@chrismaree That makes sense
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
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.
LGTM! Maybe add the caveat we discussed in the PR description.
This pr makes all return types consistent throughout the DVM by always first declaring a local variable and then returning the instance of this variable.
Note that functions that return more than 1 variable will use the named return variable standard such that implementations of contracts can read variables directly from contract reads.