theraot / Theraot

Backporting .NET and more: LINQ expressions in .net 2.0 - nuget Theraot.Core available.
MIT License
160 stars 30 forks source link

JetBrains code annotations #29

Closed NN--- closed 3 years ago

NN--- commented 5 years ago

ReSharper as well as Rider support code annotations which greatly help to write safer code. You don't need any addition NuGet package. Just add a source file with attributes such as this and ReSharper/Rider will analyze the code finding out while you write.

theraot commented 5 years ago

I will hold on this until C# 8.0 is out of beta.

NN--- commented 5 years ago

This is not strictly related to C# 8. C# 8 does bring some non nullabity but it doesn't handle several cases on purpose. You can read about limitations. JetBrains annotations can do much more as well there are other useful annotations such as CanBeNull, InstantHandler, LinqTunnel and so on. You can see their usage in CodeJam or other libraries.

theraot commented 5 years ago

I am aware this works without C# 8. However, there is overlap. There is a chance that Microsoft will add (again) a NotNullAttribute and similar. If they do, I would rather mimic what they do, and I would also hope Reshaper et.al. to support whatever Microsoft ends up with.

theraot commented 5 years ago

@NN--- See https://youtu.be/gGUYUJmssYM?t=1169

NN--- commented 5 years ago

It is not only NotNull attribute. See Contract attribute for instance or InstantHandle.

As well I don't expect everyone upgrades to C#8 right when it comes out. As well don't forget about compiler bugs :) Until then there is a little cost for making code better which work today and will work in all environments.

NN--- commented 4 years ago

C# is released with nullability but it takes time to make it useable and it doesn't contradict JetBrains annotations. https://devblogs.microsoft.com/dotnet/embracing-nullable-reference-types/

theraot commented 4 years ago

I can add a dependency to JetBrains.Annotations, which would then be deployed, I do not want to do that.

I could include the annotations in source code. Which if public would conflict with any other implementation. So... internal, right? Then are they available to projects using the library from the nuget? I do not think they are.

Then there is the option of using External Annotations. Which would work for projects using the library... then the problem is that I need to maintain the XML.

What I would want is to add the annotations in source code. And generate the XML from them to deploy.

NN--- commented 4 years ago

External with XML is a very hard work :( You can see here https://github.com/JetBrains/ExternalAnnotations

The easiest option is to add annotations file to the project . The NuGet package is only for the programs not for libraries. See example: https://github.com/rsdn/CodeJam/blob/3a3c9c984f7f4f683cda25709d8b47ff2a9bfa5b/CodeJam.Main/CodeJam.Main.csproj#L164

BTW do you use ReSharper ? You can get a free license for open source development.

NN--- commented 3 years ago

I could include the annotations in source code. Which if public would conflict with any other implementation. So... internal, right? Then are they available to projects using the library from the nuget? I do not think they are.

Using internal in the library doesn't expose them to anyone. Anyway seems like NRT solves 90% of the annotations use cases.