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

Ensure usage from correct logic will never panic: use Result where appropriate, otherwise document correct usage #13

Closed
marshallpierce opened this issue Feb 15, 2017 · 5 comments

Comments

@marshallpierce
Copy link
Collaborator

This will make it possible to guarantee panic-free codepaths.

Optionally, we might expose ways to record, read, that can panic but do not require the Result syntactic overhead.

@jonhoo
Copy link
Collaborator

jonhoo commented Feb 15, 2017

Implementing AddAssign already sort-of gives us the latter, but having named methods for this as well would probably also be a good addition.

@marshallpierce
Copy link
Collaborator Author

On further consideration, I'm not sure that a blanket "use Result everywhere" policy is actually beneficial. The potential overflow in value_for, for instance, isn't necessarily useful to expose with a Result since you will only encounter an Err if your logic is wrong and you iterate too far. As an example, what about an iterator implementation that is correctly implemented? It will have Result-handling code that is never going to hit error cases unless it has incorrect logic that tries to iterate too far.

I think a more useful goal would be something like:

  • Use Result where valid logic can still encounter an overflow, etc, error
  • In places that will always succeed unless a programmer error is made, carefully document what the result will be (e.g. "if the input cannot be represented in a u64, the result will be garbage, but it will not panic"). This means using wrapping_shl and friends to make that behavior more explicit.

@jonhoo
Copy link
Collaborator

jonhoo commented Feb 17, 2017

Yeah, you're right, that seems like a reasonable plan.

@marshallpierce marshallpierce changed the title Use Result everywhere a calculation can overflow or underflow Ensure usage from correct logic will never panic: use Result where appropriate, otherwise document correct usage Feb 18, 2017
@marshallpierce
Copy link
Collaborator Author

@jonhoo
Copy link
Collaborator

jonhoo commented Aug 30, 2017

Closing now that #55 has been merged. #38 is still a concern, but that's tracked, well, in #38.

@jonhoo jonhoo closed this as completed Aug 30, 2017
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

2 participants