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

[Bug-Candidate]: Rename "clamp" to avoid confusion #49

Open
CodeSandwich opened this issue Nov 17, 2023 · 0 comments
Open

[Bug-Candidate]: Rename "clamp" to avoid confusion #49

CodeSandwich opened this issue Nov 17, 2023 · 0 comments

Comments

@CodeSandwich
Copy link

Describe the issue:

The state

There's a set of functions in contracts/util/PropertiesHelper.sol named clamp... for making numbers fit in a fixed range by performing modulo. For example using such function to put numbers 0-10 in the range 4-6 will result in:

in:  0 1 2 3 4 5 6 7 8 9 10
out: 6 4 5 6 4 5 6 4 5 6 4

The problem

In the programming nomenclature the term "clamp" usually refers to putting number in a fixed range by assigning it the value of the boundary, if that boundary is exceeded. For example clamping numbers 0-10 in the range 4-6 would result in:

in:  0 1 2 3 4 5 6 7 8 9 10
out: 4 4 4 4 4 5 6 6 6 6 6

I'm writing this based on my experience, I got really confused when I saw PropertyHelper's clamp... functions in use for the first time. I checked my expectations by searching on the internet for "clamp a number", and all the resources were referring to "clamping" as assigning the exceeded boundary, not calculating the modulo. I think that many developers using PropertiesHelper for the first time will be confused or misled.

The solution

I think that the clamp... functions should be renamed to something less confusing. For example the name wrap... could be good, it would reflect how numbers exceeding the limit are returning into the range on the other end.

Steps to reproduce the issue:

Write code using PropertiesHelper.

If additional code is needed for reproducing, please copy it here, or drop us a link to the repository:

No response

Echidna version:

All of them.

Additional information:

No response

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

No branches or pull requests

1 participant