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 streamReader: Replace goto Statement with Loop in Recv Method #339

Merged
merged 3 commits into from
Jun 8, 2023

Conversation

YukiBobier
Copy link
Contributor

@sashabaranov I'd appreciate your review on these changes.

Description

This pull request introduces a refactor to the Recv method in the streamReader type, which improves code readability and maintainability.

Main Changes

These changes maintain the functionality of the Recv method, while improving the clarity of the control flow within the function. The goto statement can sometimes make the code hard to understand and maintain, hence this refactor aims to resolve that.

Testing

The changes have been tested to ensure that they don't introduce any regressions.

@codecov
Copy link

codecov bot commented Jun 2, 2023

Codecov Report

Merging #339 (f0a5b75) into master (6830e00) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #339      +/-   ##
==========================================
+ Coverage   93.65%   93.71%   +0.05%     
==========================================
  Files          17       17              
  Lines         646      652       +6     
==========================================
+ Hits          605      611       +6     
  Misses         30       30              
  Partials       11       11              
Impacted Files Coverage Δ
stream_reader.go 100.00% <100.00%> (ø)

@YukiBobier
Copy link
Contributor Author

@sashabaranov I've added a test and modified the branch to address the coverage issue.

@sashabaranov
Copy link
Owner

Thank you for the PR! While we optimize this section, I've got a couple of comments…

stream_reader.go Outdated Show resolved Hide resolved
respErr := stream.errAccumulator.unmarshalError()
if respErr != nil {
err = fmt.Errorf("error, %w", respErr.Error)
for {
Copy link
Owner

Choose a reason for hiding this comment

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

Due to added level of indentaion I wonder if we should factor out for body in the separate function (or maybe parts of the for body)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you. Extracting the big, deeply nested for-loop into a separate method would be a good idea.

I will do so👍

@YukiBobier
Copy link
Contributor Author

I've done this.

But hmm... Coverage issues have occurred...
I will address them.

@YukiBobier YukiBobier force-pushed the remove-goto-statement branch 2 times, most recently from 0838124 to 079a1f5 Compare June 4, 2023 04:02
@YukiBobier
Copy link
Contributor Author

@sashabaranov
I've addressed all the CI issues by adding two new tests and rebasing the branch.

Additionally, I have responded to all the comments that were made. 👍

Could you please review it again?

@sashabaranov
Copy link
Owner

@YukiBobier duh, we've got conflicts now due to other stuff

@YukiBobier
Copy link
Contributor Author

@sashabaranov Oops, I will resolve it👌

This commit adds tests to improve coverage before refactoring
to ensure that the changes do not break anything.
This commit introduces a refactor to improve the clarity of the control flow within the method.
The goto statement can sometimes make the code hard to understand and maintain, hence this refactor aims to resolve that.
This commit improves code readability and maintainability
by making the Recv method simpler.
@YukiBobier
Copy link
Contributor Author

@sashabaranov Done👍

Copy link
Owner

@sashabaranov sashabaranov left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

@sashabaranov sashabaranov merged commit b8c13e4 into sashabaranov:master Jun 8, 2023
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