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

AVRO-3503 Fix usage of 'is' and 'as' in Equals #1666

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

KyleSchoonover
Copy link
Contributor

Jira

Tests

  • My PR adds the following unit tests: Adding coverage for Equals changes

Commits

  • My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain Javadoc that explain what it does

@github-actions github-actions bot added the C# label Apr 21, 2022
@KyleSchoonover
Copy link
Contributor Author

Currently working on tests.

@zcsizmadia
Copy link
Contributor

I recommend to add the unit tests first into a different PR for each Equals code which will be changed. Once there is test coverage, the Equals code should be modified in a seperate PR.

@zcsizmadia
Copy link
Contributor

I am not sure changing to SequenceEqual is the way to go. IMO those changes have a high risk for a breaking change.

@KyleSchoonover
Copy link
Contributor Author

I can break it out into separate PR's. I'm going to use this as a bucket to check against the CI pipelines.

As for SequenceEqual, I find it better than the for loops and nested if statements as long as it is comparing simple types. I'm reluctant to use it for complex types.

@zcsizmadia
Copy link
Contributor

The complexity of reviewing the SequenceEqual change is definetely higher than the actual problem the ticket scopes for. E.g. SequenceEqual is using the default comparer EquityComparer<string>.Default. Which is in your case is the Ordinal comparison code. IMO that knowledge is not trivial and can be easily missed.

The unit tests should provide the baseline for the changes you make, unless the changes are trivial.

@zcsizmadia
Copy link
Contributor

zcsizmadia commented Apr 21, 2022

The other issue is changing the code behaviour of the Equals functions. It is standard practice to either throwing a exception if the argument is null or returning false. Some of the changes would return false instead of throwing the exception (which is the current implementation in some of those codes). Which might be ok, if we mark this PR as a major release PR, but in that case, the scope is definetely bigger than it is described in the ticket.

@KalleOlaviNiemitalo
Copy link

In general, I'd recommend having A.Equals(object obj) compare obj.GetType() == this.GetType() rather than obj.GetType() == typeof(A). This way, if another class B is derived from A, then B.Equals(object obj) can call base.Equals(obj) to compare the types and the members inherited from A. If A is a struct or a sealed class, then the JIT compiler should be able to optimize this.GetType() to typeof(A).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants