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

Code Analysis rule CA1860 gives a biased message #74179

Open
wilfriedb opened this issue Jun 27, 2024 · 0 comments
Open

Code Analysis rule CA1860 gives a biased message #74179

wilfriedb opened this issue Jun 27, 2024 · 0 comments
Assignees

Comments

@wilfriedb
Copy link

Version Used:
.Net 8

Steps to Reproduce:

  1. Type the following code:
var xs = Array.Empty<int>();
var b = xs.Any();
  1. The warning "CA1860: Prefer comparing 'Length' to 0 rather than using Any(); both for clarity and for performance" appears. (Note: for a List, the message will show 'Count' instead of 'Length'.)

I do not agree with the message. Using Any() on every collection type gives more consistency than littering you code with Length, Count and Any(). This rule is important voor performance, but not for clarity.

Maybe you disagree with my statement, but that's the point that I'm trying to make: the rule talks about clarity but there are different opinions about that. Because of this I think the message should be something just like:

"CA1860: Prefer comparing 'Length' to 0 rather than using Any() for performance"

(English is not my first language so maybe this could be phrased better than that).

Diagnostic Id:
CA1860

Expected Behavior:
CA1860: Prefer comparing 'Length' to 0 rather than using Any() for performance

Actual Behavior:
CA1860: Prefer comparing 'Length' to 0 rather than using Any(); both for clarity and for performance

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 27, 2024
@Cosifne Cosifne removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants