-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Remove unnecessary SafeMath call #1610
Conversation
Co-Authored-By: nventuro <[email protected]>
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.
Okey, I've taken a look at it. To be honest, the whole thing looks a bit like an overkill to me. After all, the whole point is to just +1 -1 a number. Having to import yet another library, and define something as using Counter for Counter.Counter
, just to do that, does not seem so friendly to me. I've got to admit that just calling .increment()
is more readable than incrementing by hand with SafeMath
though.
Anyway, I understand that the rationale behind it is to "encapsulate" the counter's value in a struct and that, if that struct was opaque, nobody could modify it. Considering that for now, the struct's value can be modified, and if it can be done, it will certainly be done, I'd still rely on SafeMath
when incrementing, just to prevent any careless developer from running into an overflow after manually overwriting the struct's value and calling increment
.
If you still want to keep it this way, I'd rather have an inline comment in the struct definition (in Counter.sol
) saying that the value is not to be modified directly, but just through increment
and decrement
. Also, I'd explicitly write a comment in the increment
function explaining why it does not use SafeMath
. Finally, it'd be nice, though maybe a bit tricky, to have tests for the overflow in increment()
.
Ah, and you should move the test file out of the drafts
folder 😛
tldr: a
I had updated the documentation, but looks like I forgot to commit that 😛
Thanks! |
I agree with @tinchoabbate's observation that "if it can be done it will be done", so I would keep the library in |
Agreed, I moved it back to |
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. Thanks!
Fixes #1552
This also takes
Counter
out of drafts, and makes it part of our API, though I guess we technically don't need to do that.