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

Apply the TimeProvider design feedback #84501

Merged
merged 4 commits into from
Apr 9, 2023

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Apr 7, 2023

Fixes #36617
Fixes #84274

This is the third and last part of the changes to TimeProvider.

@dotnet-issue-labeler dotnet-issue-labeler bot added needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners new-api-needs-documentation labels Apr 7, 2023
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned tarekgh Apr 7, 2023
@tarekgh
Copy link
Member Author

tarekgh commented Apr 7, 2023

#84235
#83604

@tarekgh tarekgh added area-System.DateTime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 7, 2023
@ghost
Copy link

ghost commented Apr 7, 2023

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

Issue Details

Fixes #84274
Fixes #36617

This is the third and last part of the changes to TimeProvider.

Author: tarekgh
Assignees: tarekgh
Labels:

new-api-needs-documentation, area-System.DateTime, needs-area-label

Milestone: -

@tarekgh tarekgh added this to the 8.0.0 milestone Apr 7, 2023
@tarekgh tarekgh requested a review from stephentoub April 7, 2023 22:52
src/libraries/Common/src/System/TimeProvider.cs Outdated Show resolved Hide resolved
src/libraries/Common/src/System/TimeProvider.cs Outdated Show resolved Hide resolved
src/libraries/Common/src/System/TimeProvider.cs Outdated Show resolved Hide resolved
src/libraries/Common/src/System/TimeProvider.cs Outdated Show resolved Hide resolved
@pinkfloydx33
Copy link

I know that #84274 decided to go with methods for the "now" properties.... but it feels Java-y and was quite weird to look at upon review.

Maybe it's because it's not consistent with a simple DateTime.UtcNow invocation. That's what it feels like it should be matched to, especially since a "now" abstraction was the driving force behind the original request. Explaining why one is a method and the other isn't--especially to a newcomer--feels like it could crop up a bit. I understand the reasoning, it just feels too inconsistent with the current static properties.

Leaving it as a UtcNow property may also help keep the diffs tidy for many of the places migrating from their own ISystemClock implementations, for whatever that is worth.

Just my 2cp

@davidfowl
Copy link
Member

I agree with leaving the properties as properties and not changing it to methods on this new abstraction. Feels weird to try and “fix things” here.

@stephentoub
Copy link
Member

stephentoub commented Apr 9, 2023

Feels weird to try and “fix things” here.

Why is it weird? This is a new abstraction. Why shouldn't we get it "right", especially when overrides can do even more than the erroneous-as-a-property UtcNow? I think the arguments made in the issue where this was discussed at length are pretty compelling. We shouldn't be relitigating it here.

(That said, I continue to be fine with it either way, but I do prefer the methods.)

@davidfowl
Copy link
Member

davidfowl commented Apr 9, 2023

I think I favor consistency over being “technically correct”. I also think about the future blog posts that continue to explain why there are differences and try to get the readers to really appreciate that mistakes were fixed. I won’t die on this hill, but I feel like these would have made a huge difference earlier and now it won’t have the same positive impact on user code (but it’ll make the design cleaner)

@stephentoub
Copy link
Member

From a consistency perspective, I think consistency with itself is more important. There are similar explanation challenges as to why it's appropriate for UtcNow/LocalNow to be properties but GetTimestamp() to be a method.

@tarekgh
Copy link
Member Author

tarekgh commented Apr 9, 2023

There are convincing strong reasons mentioned in the following comments to have them as methods.

#36617 (comment)
#36617 (comment)

Additionally, users keep complaining having UtcNow and Now as a property and even we got requests before to obsolete such Now. I don't think we need to repeat the same mistake just to be consistent.

@tarekgh tarekgh merged commit 58ea9cb into dotnet:main Apr 9, 2023
@tarekgh tarekgh deleted the TimeAbstraction-Part3 branch April 9, 2023 23:04
@davidfowl
Copy link
Member

Sure, like I said, I wouldn’t die on this hill 😅

public TimeSpan GetElapsedTime(long startingTimestamp, long endingTimestamp) { throw null; }
public abstract System.Threading.ITimer CreateTimer(System.Threading.TimerCallback callback, object? state, System.TimeSpan dueTime, System.TimeSpan period);
public virtual System.Threading.ITimer CreateTimer(System.Threading.TimerCallback callback, object? state, System.TimeSpan dueTime, System.TimeSpan period) { throw null; }
Copy link

@niemyjski niemyjski Apr 10, 2023

Choose a reason for hiding this comment

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

Question: Why would you want to throw null here? I'd expect NotImplementedException / abstract implementation.

Copy link
Member

Choose a reason for hiding this comment

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

This is the reference assembly. It should never be used at runtime, and the goal is to define just the signatures while keeping the size as small as possible. throw null is what we do in the ref assemblies everywhere.

Choose a reason for hiding this comment

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

Thanks, that makes sense!

@ghost ghost locked as resolved and limited conversation to collaborators May 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address the TimeProvider community feedback API to provide the current system time
5 participants