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

Make parsing and formatting utility method naming more accurate and consistent #925

Merged
merged 11 commits into from
Jan 23, 2025

Conversation

PaulusParssinen
Copy link
Contributor

@PaulusParssinen PaulusParssinen commented Jan 18, 2025

I have been going back and forth for long time when would be best time to try introduce these changes, so here goes.

This PR makes major naming changes in the "low-level" utility classes: NumUtils and RespRead/WriteUtils. The naming changes are largely mechanical:

  1. Adding Try-prefix to all parsing/formatting methods that return bool indicating whether reading/writing was successful or not.
    i. This matches the .NET API design convention I think majority .NET developers are/should be familiar with. I'm talking about the distinction between int.Parse and int.TryParse. It makes it clear to the developer they need to think about the case where the method can fail "silently" if the return value is ignored. Generally these Try methods are also the more performant ones, they handle the majorirty that they don't usually throw, and as such incur any exception handling costs.
  2. .NET primitive numeric naming in method names, i.e. (U)Long to (U)Int64. This one is very much preference thing, but after I saw method named as Read64Int, I went ahead with this naming change proposal. (This is also the convention in BCL)
  3. PR also attempts to improve the xmldoc situation in NumUtils.

Method naming is largely very subjective and hard, but I think these changes are warranted as I believe they improve readability and reduce the mental overhead when working with the parsing/formatting parts of the code-base. I also think that more accurate method naming conventions especially improve code-review process.

I'm very happy and prefer to wait with this PR to minimize any all the conflicts this will have with older PRs still in progress.

…I patterns

* Also makes them more consistent with RespRead/WriteUtils naming
* Revamp xmldoc comments.
* Includes some adjustments in consumption of these methods, no behavioral changes.
…ead/WriteUtils.

* This makes it the assumptions of the method much more visible to callers.
* NumUtils.TryReadDouble/Int64 has no (sane) situatioin it would throw on here.
…tency.

Add exception throwing xmldoc details to TryRead methods
@TalZaccai TalZaccai self-requested a review January 21, 2025 19:19
@badrishc
Copy link
Contributor

I think this is a good and sensible code clean-up, we should review and get this merged.

Copy link
Contributor

@TalZaccai TalZaccai left a comment

Choose a reason for hiding this comment

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

Big fan of this PR! :) Thanks for taking the time to do this!

@TalZaccai TalZaccai merged commit c5b43eb into microsoft:main Jan 23, 2025
15 checks passed
@PaulusParssinen PaulusParssinen deleted the io-naming branch January 23, 2025 23:23
@badrishc badrishc mentioned this pull request Jan 27, 2025
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.

3 participants