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

Improve docs for BinaryData.ToString() #56325

Merged
merged 3 commits into from
Aug 11, 2021
Merged

Conversation

JoshLove-msft
Copy link
Contributor

No description provided.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@GrabYourPitchforks
Copy link
Member

In general I don't have a concern with clarifying docs, but it does strike me as a bit weird to call out JSON string behavior specifically. Why are JSON strings promoted to a first-class citizen within the remarks section, but JSON objects/arrays aren't mentioned, and weirdness resulting from <arbitary binary data>.ToString() not called out? Is this doc change motivated by seeing how people are using / misusing this API in practice? And if that's the case, is a code analyzer a better alternative to doc updates?

@JoshLove-msft
Copy link
Contributor Author

JoshLove-msft commented Jul 27, 2021

In general I don't have a concern with clarifying docs, but it does strike me as a bit weird to call out JSON string behavior specifically. Why are JSON strings promoted to a first-class citizen within the remarks section, but JSON objects/arrays aren't mentioned, and weirdness resulting from <arbitary binary data>.ToString() not called out? Is this doc change motivated by seeing how people are using / misusing this API in practice? And if that's the case, is a code analyzer a better alternative to doc updates?

Yes, this is motivated by users not understanding how to get a JSON string and being confused by the output from ToString. I'm not sure how an analyzer would work in general here as we would not be able to tell whether it is a valid ToString usage or not. The main goal is to just introduce the idea of ToObectFromJson<string>, as it isn't obvious to users that they would need to do this.

@ghost
Copy link

ghost commented Jul 28, 2021

Tagging subscribers to this area: @GrabYourPitchforks, @dotnet/area-system-memory
See info in area-owners.md if you want to be subscribed.

Issue Details
Author: JoshLove-msft
Assignees: -
Labels:

area-System.Memory

Milestone: -

@GrabYourPitchforks
Copy link
Member

we would not be able to tell whether it is a valid ToString usage or not.

@JoshLove-msft What would a "valid" ToString usage look like for this type? From my understanding of the type, this type is a literally a container for arbitrary binary data. That would imply that the only "correct" way to convert this to a human-readable representation is for the caller to signal what the data represents and thus what transform is valid: JSON unwrapping, UTF-8 conversion, hex conversion (for binary data), etc. I'm almost tempted to suggest marking the ToString method as [Obsolete] in addition to putting in the doc comment.

@bartonjs Do you have thoughts on this? In recent reviews you've mentioned concerns about users calling ToString on various exchange types while harboring incorrect assumptions about just what the ToString method does.

Copy link
Member

@GrabYourPitchforks GrabYourPitchforks left a comment

Choose a reason for hiding this comment

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

Approved to unblock this since it's an improvement over the current situation. But per feedback in the issue conversation, I think relying solely on docs is the wrong long-term solution, and we need to think about more in-your-face mechanisms to steer users toward correct behaviors.

@JoshLove-msft
Copy link
Contributor Author

JoshLove-msft commented Jul 29, 2021

we would not be able to tell whether it is a valid ToString usage or not.

@JoshLove-msft What would a "valid" ToString usage look like for this type? From my understanding of the type, this type is a literally a container for arbitrary binary data. That would imply that the only "correct" way to convert this to a human-readable representation is for the caller to signal what the data represents and thus what transform is valid: JSON unwrapping, UTF-8 conversion, hex conversion (for binary data), etc. I'm almost tempted to suggest marking the ToString method as [Obsolete] in addition to putting in the doc comment.

ToString does UTF-8 conversion, so any UTF-8 encoded bytes would be valid. It isn't necessarily invalid to call ToString on JSON, it is just probably not want the user wants in most cases, since there are special JSON deserialization methods on BinaryData. A case where it makes sense to use ToString would be when you are using some other textual represenation, e.g. plaintext, or XML, where BinaryData does not also have specialized methods for handling those formats. In those cases, ToString makes sense. I agree that it is somewhat ambiguous, and that this is something of a usability bandaid.

@ghost
Copy link

ghost commented Aug 11, 2021

Hello @adamsitnik!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

I've applied all the suggestions and pushed them directly to @JoshLove-msft branch. LGTM

@adamsitnik
Copy link
Member

Failures are unrelated (#56894), merging

@adamsitnik adamsitnik merged commit a4f1b6e into dotnet:main Aug 11, 2021
@danmoseley
Copy link
Member

Note this won't appear on the docs site until we run the porting tool again. If the goal is to get the changes on the doc site it's probably easiest to create another PR against dotnet/dotnet-api-docs.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants