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

IComparable for complex params #2304

Merged
merged 7 commits into from
May 10, 2023

Conversation

mrahhal
Copy link
Contributor

@mrahhal mrahhal commented May 9, 2023

All the types in PrimitiveComparer are actually already IComparable, so I feel we can just remove this whole part altogether and have a single implementation that uses IComparable. Thoughts?

Not sure if just removing it will replicate current behavior, since it does some stuff with enums, and it also even does a string comparison (which feels weird to me since there's already a string comparison in ParameterComparer.Compare).

Closes #2301

@mrahhal mrahhal marked this pull request as draft May 9, 2023 20:13
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it LGTM, I just left one suggestion for improvement.

@mrahhal thank you for your contribution!

src/BenchmarkDotNet/Parameters/ParameterComparer.cs Outdated Show resolved Hide resolved
@mrahhal mrahhal marked this pull request as ready for review May 10, 2023 10:31
@AndreyAkinshin
Copy link
Member

It looks great, thanks! The only suggestion I have is about the intro example. We are trying to keep them as small as possible. I would suggest removing non-essential comments (e.g., "property with public setter", "public property") and simplifying some of the methods. E.g., instead

public int CompareTo(ComplexParam other)
{
    if (other == null)
    {
        return 1;
    }

    return Value.CompareTo(other.Value);
}

we can write

public int CompareTo(ComplexParam other) => other == null ? 1 : Value.CompareTo(other.Value);

@AndreyAkinshin
Copy link
Member

@mrahhal could you please also rewrite IntroComparableComplexParam.CompareTo(object obj)? Currently, it occupies too much space in the sample (while this particular implementation is not so important).

@mrahhal
Copy link
Contributor Author

mrahhal commented May 10, 2023

Sure. Simplified it as much as I can.

Copy link
Member

@AndreyAkinshin AndreyAkinshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AndreyAkinshin AndreyAkinshin merged commit f32a2e7 into dotnet:master May 10, 2023
@AndreyAkinshin
Copy link
Member

@mrahhal thanks for your contribution!

@AndreyAkinshin AndreyAkinshin added this to the v0.13.6 milestone May 10, 2023
@mrahhal mrahhal deleted the icomparable-for-complex-params branch May 10, 2023 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom order of parameters when using complex types
3 participants