-
Notifications
You must be signed in to change notification settings - Fork 158
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
size-suggestion: Consider merging getNextTransition/getPreviousTransition into one with a direction option #2850
Comments
This would be a big ergonomic loss IMO. |
I'm neutral on this one. The methods would certainly become more annoying to use, but I don't expect they are used very often. |
My origional proposal at https://docs.google.com/document/d/16Rd43XB8z6iLC2c9AfF--unDFg_t476tI1PFe7PbbcM/edit#heading=h.xs8xipj8fzpn
For those developers who "at development time when the expected data type and semantics of direction are not necessarily at hand", how would they decide how to write their code to call getNextTransition or getPreviousTransition ? |
The scenario is that they know that they want e.g. the next transition, but not how to specify that for a combined method (e.g., |
hum? why? They can read MDN the same way as they read MDN to learn about how to call getNextTransition and getPreviousTransition right? |
Sometimes, but sometimes not. And regardless, we don't want APIs to be so opaque that such lookups are necessary—once someone learns about a function, further confusion regarding how to use it (and often more importantly, how to read it) should be minimized. This is the same reason why we prefer property bags to long parameter lists, why "SmooshGate" was such a big deal, why we have String {pad,trim}{Start,End} and {starts,ends}With methods, why |
@gibson042 be aware, when I draft Ideas to Reduce Temporal API Surface without Reducing Functionality, it is written as a counterproposal to issues/2826 which remove all TimeZone protocol, including getNextTransition/getPreviousTransition . I think it is much ergonomic to support one function getTransition than none of them. No code could be discovered if they got removed from the Temporal proposal. so the choices facing us is
|
@FrankYFTang see #2853 (emphasis mine):
|
I don't think my point of view is very important here because this is a rare expert feature, so I don't think we need to care a gigantic amount about ergonomics. But it feels slightly wrong to merge two functions and then control which one you're accessing with a flag--I wouldn't normally want to design an API like this. This change seems like overfitting to the current state of V8. |
but... why this need to be one function? The only differences between then is one call And then if you read the only differences between them is one states "the first time zone transition after epochNanoseconds" and there are no other differences beyond that. |
Meeting 2024-05-23: At the upcoming June 2024 TC39 plenary meeting, we'll propose removing the TimeZone type (see #2853). So An added possible advantage of the change is that we can change the name of the new method to include "TimeZone" in the method name (which is important context for users because it will now be on ZDT instead of on a TimeZone class) without having to also include Next and Previous in the method name which would balloon its length. The champions did want to make clear that we strongly agree with the comments from @littledan above: turning separate methods into a parameter on merged method is a step backwards in usability. We're OK to it here because these are advanced-user-only methods, but in general we will not be doing this kind of parameterized multiplexing because it degrades discoverability without actually removing complexity from the API for implementers or userland developers. I'll follow up this comment to kick off bikeshedding the new method name and the parameter shape and values. |
I'll kick off the bikeshedding for this merged method. Feel free to add more ideas or add your feedback! FYI @sffc @ptomato @gibson042 @gilmoreorless @arshaw @ctcpip for your thoughts. Method names
Parameter shapes
String enumeration parameter values
|
TC39 has previously recommended using the I think my preference would be zdt.getTimeZoneTransition({ direction: "..." }) I think I prefer I prefer an options bag because this option configures the behavior, and the argument is not described in the function name like it is in the handful of positional argument functions we have like Question: are these inclusive-next or exclusive-next? What happens if you call them on a time zone transition itself? zdt.getTimeZoneTransition({ direction: "next" }).getTimeZoneTransition({ direction: "next" }) If they are inclusive-next, you can always skip ahead by adding 1 nanosecond before calling |
They're exclusive. it starts looking 1ns before or 1ns after the receiver. |
I think it's important to reference some sort of "movement" in the method name to avoid this misinterpretation: if (!zdt.getTimeZoneTransition()) {
console.log('A time zone transition does not occur at the given ZonedDateTime!')
}
// ^^^obviously wrong because the API returns the *next* transition,
// NOT whether a transitions happens AT the given ZonedDateTime Out of all the "movement" words we could choose ("next" / "later" / "forward"), I like "next" the best because it's generic enough to be used for either direction. The following is my preference: // moving towards future (default)
zdt.getNextTransition()
// moving towards past
zdt.getNextTransition({ reverse: true }) |
Meeting 2023-05-30: We will merge these two methods into a new It will accept a single required argument which must be either |
Done in #2914. |
Should we merge
getPreviousTransition
andgetNextTransition
into a single method like this?This issue is adapted from suggestions made by @FrankYFTang to help reduce the size of Temporal to address concerns from implementers (especially Android and Apple Watch) that Temporal's install size and/or in-memory size is too large.
This would be especially worth considering if we remove the Time Zone class (see #2826) and have to move this functionality into the ZonedDateTime type, so we'd end up with something like this:
The text was updated successfully, but these errors were encountered: