2

I've began studying how the .NET Code Analysis works. It seems that it can be either enabled via a NuGet package or a property in the SDK-style *.csproj files. Also, starting in .NET 5, it is enabled by default.

I'm surprised to discover that most of the rules are disabled by default. I can understand that some of them have been deprecated or replaced with compiler warnings, and that others may be unimportant or contradictory, so it's preferable to disable them by default to avoid drowning the poor developers in more warnings that they can possibly address. However, it's not hard to find many disabled rules that seem important and that could lead to early detection of bugs, like CA2100.

So my question is: What is the rationale explaining why some rules are disabled?

1 Answer 1

4

Two likely answers:

  • turning it on would flag a lot of existing code
  • the code analyser was developed for internal Microsoft "dogfooding" purposes

For example, I don't think https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1014 or https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1021 would be very popular in general purpose code.

1
  • Now that we have tuples there's not really any reason for out parameters other than in pre-tuple code. Commented Nov 18, 2023 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.