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

[API Proposal]: Rename INumber<T>.Create<TOther> to CreateNumber<TOther> #65921

Closed
SpocWeb opened this issue Feb 26, 2022 · 4 comments
Closed
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Numerics

Comments

@SpocWeb
Copy link

SpocWeb commented Feb 26, 2022

Background and motivation

I am pleased with the Pattern established by INumber.Create which obviously allows to convert Values between different generic Implementations of INumber.

But applying two or more of this Patterns (from different Interfaces than INumber< T>) on the same Type, easily leads to a Name Clash.
I therefore ask for a more descriptive Name that also conveys the Intention better.

By renaming INumber<T>.Create<TOther> to CreateNumber<TOther> or even better: CreateNumberFrom<TOther>(other) Conflicts are much less likely.

API Proposal

namespace System
{
    public interface INumber<TSelf>
    {
	static abstract TSelf CreateNumber<TOther>(TOther other);
    }
}

API Usage

	public static T ConvertFrom<T, TN>(TN value)
		where T : INumber<T>
		where TN : INumber<TN> {
		return T.CreateNumber(value);
	}

Alternative Designs

Of course you can also leave the Name ´Create´ but that makes it harder for future Developments.
In Fact, it is desirable to define additional new CreateXxx< TOther> Methods for smaller Sub-Interfaces of INumber< T> as proposed here.

Risks

Since the System.INumber API is not final yet, the change is unproblematic.
Since the Change will result in a Compile Error, it is very prominent and will not lead to hidden Problems.

@SpocWeb SpocWeb added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Feb 26, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Feb 26, 2022
@ghost
Copy link

ghost commented Feb 26, 2022

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

I am pleased with the Pattern established by INumber.Create which obviously allows to convert Values between different generic Implementations of INumber.

But when applying two or more of this Pattern on the same Type, leads to a Name Clash.
I therefore ask for a more descriptive Name that also conveys the Intention better.

By renaming INumber<T>.Create<TOther> to CreateNumber<TOther> Conflicts are much less likely.

API Proposal

namespace System
{
    public interface INumber<TSelf>
    {
	static abstract TSelf CreateNumber<TOther>(TOther other);
    }
}

API Usage

	public static T ConvertFrom<T, TN>(TN value)
		where T : INumber<T>
		where TN : INumber<TN> {
		return T.CreateNumber(value);
	}

Alternative Designs

Of course you can also leave the Name ´Create´ but that makes it harder for future Developments.

Risks

Since the System.INumber API is not final yet, the change is unproblematic.
Since the Change will result in a Compile Error, it is very prominent and will not lead to hidden Problems.

Author: SpocWeb
Assignees: -
Labels:

api-suggestion, area-System.Numerics, untriaged

Milestone: -

@tannergooding
Copy link
Member

Thanks for the suggestion here. I agree that the potentially conflicting name here might be problematic and it's something I will raise with API review.

@tannergooding tannergooding removed the untriaged New issue has not been triaged by the area owner label Mar 3, 2022
@tannergooding
Copy link
Member

tannergooding commented May 8, 2022

The current proposal/implementation has the names as CreateChecked, CreateSaturating, and CreateTruncating: dotnet/designs#262

@ghost ghost locked as resolved and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Numerics
Projects
None yet
Development

No branches or pull requests

3 participants