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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor(capi): make early returns consistent in C examples #2812

merged 7 commits into from
Apr 12, 2022

Refactor(capi): make early returns consistent in C examples #2812

merged 7 commits into from
Apr 12, 2022


Copy link

Hello there! I saw the blog posts regarding this project's campaign for 1.0. 馃コ

I figured I could help out with the C examples by making the code style regarding early returns more consistent. I found that (prior to this PR) the examples tended to mix between coding styles. On a personal note, I much prefer reading code with early returns anyway since there are less indentations/nested braces to worry about. 馃槄

So with that said, this PR simply refactors instances of nested error-handling logic as early returns. The result is more "linear" code with less indentations. Hooray!

To help make the review easier, I have also separated the commits into the specific decisions I took while refactoring. Hope this helps out a little bit with the documentation for the C API. Thanks!

Since the `if` condition already causes the loop to `break`,
the `else` is not necessary. We wouldn't have reached the `else`
block, anyway, if the prior `if` condition passed.
We are more likely to poll a successful chunk than finish
the request or throw an error. Thus, it is best if we go
for the optimistic route and check for the successful
case first.
Copy link

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

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

Thanks for making things more consistent 馃槉

@seanmonstar seanmonstar merged commit 1d895b8 into hyperium:master Apr 12, 2022
@BastiDood BastiDood deleted the examples/refactor-c-examples branch April 24, 2022 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants