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

feat: use the < operator instead of cmp method to improve readability #10268

Merged
merged 1 commit into from Nov 30, 2023

Conversation

jancionear
Copy link
Contributor

The following code is currently used for comparing boundary_account and account_id:

if boundary_account.cmp(account_id) == Greater {
    ...
}

IMO it's a bit confusing - it isn't immediately obvious whether this means boundary_account > account_id or account_id > boundary_account. I misread this line and because of that I made a mistake in #10240.

Let's change it to something that is easier to read:

if account_id < boundary_account {
    ...
}

The following code is currently used for comparing `boundary_account` and `account_id`:
```rust
if boundary_account.cmp(account_id) == Greater {
    ...
}
```

IMO it's a bit confusing - it isn't immediately obvious whether this means `boundary_account` > `account_id`
or `account_id` > `boundary_account`. I misread this line and because of that I made a mistake in near#10240.

Let's change it to something that is easier to read:
```rust
if account_id < boundary_account {
    ...
}
```
@jancionear jancionear requested a review from a team as a code owner November 29, 2023 18:48
Copy link

codecov bot commented Nov 29, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (dd80b4c) 71.91% compared to head (cae8e8c) 71.89%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10268      +/-   ##
==========================================
- Coverage   71.91%   71.89%   -0.02%     
==========================================
  Files         707      707              
  Lines      142268   142268              
  Branches   142268   142268              
==========================================
- Hits       102306   102286      -20     
- Misses      35237    35255      +18     
- Partials     4725     4727       +2     
Flag Coverage Δ
backward-compatibility 0.08% <0.00%> (ø)
db-migration 0.08% <0.00%> (ø)
genesis-check 1.26% <0.00%> (ø)
integration-tests 36.25% <100.00%> (-0.04%) ⬇️
linux 71.77% <100.00%> (+<0.01%) ⬆️
linux-nightly 71.47% <100.00%> (-0.04%) ⬇️
macos 55.09% <100.00%> (+0.01%) ⬆️
pytests 1.49% <0.00%> (ø)
sanity-checks 1.28% <0.00%> (ø)
unittests 68.26% <100.00%> (-0.01%) ⬇️
upgradability 0.13% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@akhi3030 akhi3030 left a comment

Choose a reason for hiding this comment

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

Thank you, much cleaner! Did you consider doing a grep for other instances of cmp that could be replaced with a simpler compare?

@jancionear
Copy link
Contributor Author

Did you consider doing a grep for other instances of cmp that could be replaced with a simpler compare?

I ran the grep, but I didn't find any other cases where I could justify replacing cmp with a binary operator. In most places cmp is used as intended - for functions that return Ordering, in sort_by, etc

@akhi3030
Copy link
Collaborator

Did you consider doing a grep for other instances of cmp that could be replaced with a simpler compare?

I ran the grep, but I didn't find any other cases where I could justify replacing cmp with a binary operator. In most places cmp is used as intended - for functions that return Ordering, in sort_by, etc

Thanks for inspecting!

@jancionear jancionear added this pull request to the merge queue Nov 30, 2023
Merged via the queue into near:master with commit 426b283 Nov 30, 2023
18 of 19 checks passed
@jancionear jancionear deleted the greater-comparison branch November 30, 2023 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants