Skip to content

Simplify type cast and remove error handling in protobuf exercise #2755

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

randomPoison
Copy link
Collaborator

While using .try_into().expect() is the more robust solution, I think it's more complex than we want here. We don't really care about error handling in this exercise, so I think a simple as cast is clearer here. I think we should also remove the logic for checking if there are enough bytes left, since it simplifies things and makes the solution easier to read.

Copy link
Collaborator

@djmitche djmitche left a comment

Choose a reason for hiding this comment

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

In other cases where we've removed something that would be likely in "real" Rust, we've gotten more than one PR trying to put it back. I think it would help to add some commentary here to indicate this is omitted deliberately. Maybe that's as simple as "// TODO: Handle invalid lengths"? That would be enough to fend off any PRs, and also provide a jumping-off point for instructors to talk about what might go wrong here (e.g., split_at might panic) and how to handle it.

@randomPoison
Copy link
Collaborator Author

Hm yeah I've noticed that sometimes things I remove for simplicity end up back in the slides. That's kind of frustrating but I get why it's happening.

Maybe that's as simple as "// TODO: Handle invalid lengths"?

I think if we put a TODO in there we're just going to get PRs trying to fix the TODO 😅. Maybe it would make sense to add something to the contribution docs stating that we want to air on the side of simplicity and clarity in the code examples and exercises, even when that makes the code less idiomatic. I don't that that'd stop the PRs, but it'd give us something to point to when somebody tries to make the code more "idiomatic" in a way that distracts from the point of the example/exercise.

@djmitche
Copy link
Collaborator

That's a good idea, too, but depends on a PR author or reviewer recognizing that this is one of those err-on-the-side-of-simplicity cases. It's a shame we can't easily have comments in the source that aren't rendered in the book.

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.

2 participants