-
Notifications
You must be signed in to change notification settings - Fork 26
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
Annotations for cases the analyzer can't figure out. #126
Comments
An alternative is to rely on doc comments, or both. Ownership of disposables is a reasonable thing to document. |
IMO, having the ability to annotate at class? interface? level is good to have to provide a default behavior for all of its members, and thus avoid having to annotate every member that returns a I would probably flag the lack of comment separately. That way we get reminder to document our methods and you get to avoid the complexity of parsing the doc comments to decide which behavior to apply. |
After thinking about it more - I'm convinced that I'd rather have those annotations be on the interfaces and its members rather than classes and its members. We do not want this scenario:
Requiring the class to implement an interface to get the use of annotation seems preferable than to run into this messy scenario. This also conveniently fixes the problem of where analyzer cannot reason about the implementation due to us passing around interfaces. |
Do you have suggestions for what an annotation ~API using attributes could look like? The stuff I wrote in the issues start was just a quick suggestion without much thought. Just keep ideas coming and we can do some voting with 👍 and 👎 and see if we can agree. It should definitely not be me deciding. Also @jeremyVignelles @milleniumbug & everyone. |
I think the return decorations covers by far the large majority of the problems we would encounter with resolving the ownership. Regarding the parameter annotation, TBH this feels funky to me to be calling a method that will dispose a passed-in object. I'd rather encourage the design where the caller will dispose the object rather than the callee. Also, as I mentioned in issue #127, it might be useful to know that a method must dispose those that weren't returned while leaving up to the caller to dispose the returned. |
@bclothier : IIRC, this is what StreamReader does with the stream, right? |
@jeremyVignelles The thing is that it's for a constructor, not for a method. I think that's the crucial difference, isn't it? You can't have a constructor on an interface; only an abstract class. Are you referring to this CompositeDisposable? It says it's going to be deprecated? |
What's the difference between a class and an interface from the analyzer's point of view? |
As mentioned earlier, we should not have annotations on a concrete class which may be provided as interface or we fall in the situation where class A caches but class B doesnt. The consumers using an interface implemented by both is now screwed. Enforcing the annotation on only interfaces or abstract classes(?) ensures that all implementations must be consistent in how they will handle the disposables. |
I didn't read the full conversation yet. |
You need to enforce whether implementing/overriding method doesn't introduce extra requirements in the contract (in the LSP sense). |
Made a PR with draft names, please review & comment. |
Not sure what attributes are needed and how we should word things. Also should probably not require a dependency on a nuget with attributes. Does JetBrains.Annotations have something for this?
The text was updated successfully, but these errors were encountered: