Skip to content
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

Merged
merged 20 commits into from
Apr 17, 2020
Merged

Conversation

chrismaree
Copy link
Member

@chrismaree chrismaree commented Apr 13, 2020

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.

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
@chrismaree chrismaree changed the title Updated named return values [P1-N09] Only return named variables Apr 13, 2020
@chrismaree chrismaree marked this pull request as ready for review April 13, 2020 10:48
@chrismaree chrismaree added the audit-fix-phase1 Fixes for Phase 1 (DVM) of the OZ audit label Apr 13, 2020
Copy link
Member

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

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

Looks great

Copy link
Member

@mrice32 mrice32 left a 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.

core/contracts/oracle/implementation/Voting.sol Outdated Show resolved Hide resolved
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>
Copy link
Member

@mrice32 mrice32 left a 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>
Copy link
Member

@mrice32 mrice32 left a 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]);
Copy link
Member Author

@chrismaree chrismaree Apr 16, 2020

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:

  1. 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.
  2. accept the small hit in code readability and ensure to always add comments for code readability.

Copy link
Member Author

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.

Copy link
Member

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>
Copy link
Member

@mrice32 mrice32 left a 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.

@chrismaree chrismaree merged commit 98df559 into master Apr 17, 2020
@chrismaree chrismaree deleted the named-return-variables branch April 17, 2020 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-fix-phase1 Fixes for Phase 1 (DVM) of the OZ audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants