-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add document for ambiguity handling #37795
base: main
Are you sure you want to change the base?
Conversation
Hi @pshao25. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days. |
Hi @pshao25. Thank you for your contribution. Since there hasn't been recent engagement, we're going to close this out. Feel free to respond with a comment containing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's audience of this doc? the SDK users or codegen?
What's the main purpose of this doc? To describe how to resolve ambiguity or show the protocol/convenience methods generated?
We may need to rearrange the content and the chapter according to the audience and purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love @chunyu3's comment #37795 (review)!
To add to @chunyu3's thoughts, it might be helpful to think about how this document works in the context of larger documentation efforts. I know @jsquire and @scottaddie have been thinking about this, and may be able to help describe the overarching effort here.
I'm also curious ... is this what we're doing today, or does it take into account future plans described by @KrzysztofCwalina in System.ClientModel Method Conventions (github.com)
@annelo-msft @chunyu3 The audience are the codegen users (i.e., service team) who are curious about the logic how the signature of method is generated.
For sure. But seems customer is asking for this document so I think we could continue this PR, and after we decide how to refactor we could move this page to that efforts.
This is what we are doing today. It doesn't take any non-branding cases into account. |
Hi @pshao25. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days. |
Hi @pshao25. Thank you for your contribution. Since there hasn't been recent engagement, we're going to close this out. Feel free to respond with a comment containing |
- If the protocol method hasn’t been GAed, the first solution is taken if there exists an ambiguous call. | ||
- If the protocol method is already GAed, the second solution is taken because we cannot change protocol method anymore. | ||
|
||
## Scope of ambiguity we handle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this standalone section of "edge cases" is making the following content a bit off-topic.
Could we make it a note of the section of Solution
?
|
||
## Scope of ambiguity we handle | ||
|
||
Not all the pairs of protocol method and convenience method will have such problem. Below is a case when there is no ambiguity if users are calling normally by passing a `model` or a `content`. (They could not pass in `null` because it will throw error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here we should summarize this section in case people would fixate on edge cases and ignoring the problem we are trying to solve such as:
It is impossible that the ambiguities could always be fixed when the two methods are overloads of each other, because of the existence of default
. We could always use the default
keyword which is acceptable by any parameter to construct a scenario that the compiler would complain about ambiguities of invocation. Therefore our goal is not solving all cases of the ambiguities, for the following cases, we will allow them to have ambiguities: ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I see we have two principals in this section, we should emphasize them first and then have examples.
@@ -0,0 +1,225 @@ | |||
# Handle Ambiguity Between Protocol Method and Convenience Method | |||
|
|||
## Background |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of Background
, i think this is more of a Problem
corresponding to the Solution
we have below.
Then we find these calls are fine, so just keep these signatures. | ||
|
||
## Appendix | ||
### Convenience method not always generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Convenience method not always generated | |
### Convenience methods are not always generated |
... | ||
} | ||
``` | ||
The convenience method has a required parameter `requiredId` and protocol method has a required method `content`, so what we guarantee will not have ambiguity are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convenience method has a required parameter `requiredId` and protocol method has a required method `content`, so what we guarantee will not have ambiguity are | |
The convenience method has a required parameter `requiredId` and protocol method has a required parameter `content`, therefore we guarantee the following invocations will not have ambiguities: |
|
||
## Examples | ||
|
||
### Operation without input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the word input is quite ambiguous. requiredId
is also an input in the following example.
Should it be Operations without request body
?
} | ||
``` | ||
We don't generate convenience method for this case (see [this](#convenience-method-not-always-generated) to see why), so there will be no ambiguity. | ||
### Operation with spread scenario |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Operation with spread scenario | |
### Operation with spread parameters |
|
||
## Appendix | ||
### Convenience method not always generated | ||
There is one [situation](#operation-without-both-input-and-output) we don't generate convenience method. Think about what would be like if we generate the convenience method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one [situation](#operation-without-both-input-and-output) we don't generate convenience method. Think about what would be like if we generate the convenience method. | |
There is one [situation](#operation-without-both-input-and-output) we don't generate convenience method, because if we did, the convenience method would have almost exact the same parameter list as the protocol method: |
... | ||
} | ||
``` | ||
The convenience method is just a wrapper and doesn't have any value. So, we just skip generating it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convenience method is just a wrapper and doesn't have any value. So, we just skip generating it. | |
The convenience method is just a wrapper therefore it is not generated. |
### Special values not taken into ambiguity consideration | ||
Think about these totally valid overloads that you've seen many times in your daily development. | ||
```C# | ||
class IntModel | ||
{ | ||
public int Value {get; set;} | ||
} | ||
|
||
class DoubleModel | ||
{ | ||
public double Value {get; set;} | ||
} | ||
|
||
int Add(IntModel a, IntModel b) | ||
{ | ||
return a.Value + b.Value; | ||
} | ||
double Add(DoubleModel a, DoubleModel b) | ||
{ | ||
return a.Value + b.Value; | ||
} | ||
``` | ||
When calling `Add(null, null)` or `Add(default, default)` or `Add(new(), new())`, ambiguity error still exists. Therefore we don't care about `null`, or `default`, or `new()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this is necessary to explain, or at least it should not be here as an appendix - it is against the normal reading sequence on human. No one would read a document like this.
In the other comment, I have suggested that we put the reason in the above sections as a note.
Hi @pshao25. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days. |
Contributing to the Azure SDK
Please see our CONTRIBUTING.md if you are not familiar with contributing to this repository or have questions.
For specific information about pull request etiquette and best practices, see this section.