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

Replace unused out arguments with discards #2726

Merged
merged 2 commits into from
Jul 29, 2024

Conversation

benrr101
Copy link
Contributor

Description: C# 7.0 added support for discards, such that if an out variable is not used after the call to a method that sets it, it can be replaced with _ to discard to value. There are around 90 instances of this in the codebase, and they are very easy to remove. As far as I can tell this makes no semantic difference to the code, but does clean up the code a bit and bring it up to a more modern standard.

The only real argument I could see against making this quick cleanup change is that it reduces the understanding of what the code aims to do. I feel this change is fairly neutral, but please feel free to disagree as necessary.

Testing: Projects still build so it should be good 👍

@benrr101 benrr101 added the ➕ Code Health Changes related to source code improvements label Jul 26, 2024
@DavoudEshtehari DavoudEshtehari added this to the 6.0-preview1 milestone Jul 26, 2024
Copy link
Member

@DavoudEshtehari DavoudEshtehari left a comment

Choose a reason for hiding this comment

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

@benrr101 Thank you for cleaning them up. I believe discarding the redundant arguments makes the code clearer and easier to follow by eliminating distractions.😉

@benrr101
Copy link
Contributor Author

@roji @cheenamalhotra I did a sweep of all the typed discards and removed all the ones I could. This likely touched some files that were untouched before this, but it's verified at compilation. There was one locations that couldn't be changed and that was due to it being ambiguous call if the type was omitted.

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 76.38889% with 17 lines in your changes missing coverage. Please review.

Project coverage is 71.75%. Comparing base (f7ab115) to head (dc20537).
Report is 43 commits behind head on main.

Files Patch % Lines
.../netcore/src/Microsoft/Data/SqlClient/TdsParser.cs 69.23% 4 Missing ⚠️
...core/src/Microsoft/Data/SqlClient/SqlDataReader.cs 62.50% 3 Missing ⚠️
...etfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs 62.50% 3 Missing ⚠️
...t/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs 75.00% 2 Missing ⚠️
...nt/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs 77.77% 2 Missing ⚠️
...fx/src/Microsoft/Data/Common/DBConnectionString.cs 0.00% 1 Missing ⚠️
...c/Microsoft/Data/Interop/SNINativeMethodWrapper.cs 66.66% 1 Missing ⚠️
...netfx/src/Microsoft/Data/SqlTypes/SqlFileStream.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2726      +/-   ##
==========================================
- Coverage   72.81%   71.75%   -1.06%     
==========================================
  Files         311      308       -3     
  Lines       61694    62301     +607     
==========================================
- Hits        44922    44707     -215     
- Misses      16772    17594     +822     
Flag Coverage Δ
addons 92.88% <ø> (ø)
netcore 76.01% <80.55%> (-1.17%) ⬇️
netfx 69.72% <75.60%> (-0.73%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@benrr101 benrr101 merged commit 8595644 into dotnet:main Jul 29, 2024
131 checks passed
@benrr101 benrr101 deleted the russellben/discards branch July 29, 2024 21:05
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
➕ Code Health Changes related to source code improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants