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

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

Merged
merged 7 commits into from
Apr 12, 2022
Merged

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

merged 7 commits into from
Apr 12, 2022

Conversation

BastiDood
Copy link
Contributor

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
Member

@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants