-
Notifications
You must be signed in to change notification settings - Fork 156
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-suggestions: Consider removing all toXxx
conversion functions
#2848
Comments
My origional suggestion could be found in https://docs.google.com/document/d/16Rd43XB8z6iLC2c9AfF--unDFg_t476tI1PFe7PbbcM/ As what we have in the spec today, if we do not change our proposal, is there functionality that
cannot produce but
can? |
I simply do not understand why we need both a X.from and a toX methods in the propoal. And if these two right now provide different functionality, that will be even more confusing and difficult for developers to choose which one to use. |
Developers will choose based on the value they're starting from—like |
The Having used the Temporal API intensively for several years, I've found find that these conversions are very, very common. It's rare for a non-trivial Temporal use case that doesn't do any conversion. The code sample I added to the OP (and that @gibson042 edited a bit) is a good illustration in the difference in usability, complexity, and code size between using chainable Another advantage of the That said, some conversion paths are more important than others. In particular, some conversions (like ZDT or PDT => PlainMonthDay or PlainYearMonth) are both uncommonly used and have easy two-step chained workarounds, so I'd be OK to remove the following conversions:
I would also be willing to discuss removing these two conversions because they've always been ergonomically awkward. Also, because both of them only transfer two properties (three if there's a calendar), the alternative of using
Also, the PlainDate => wider type conversion is much more commonly needed than the PlainTime => wider type conversion, so we could perhaps remove these two conversions by pushing users to convert from dates => wider by adding times, instead of from times => wider by adding dates. This would remove two more functions:
Finally, I'd be OK to remove The suggestions here in this comment would remove 9 of the 21 conversion methods, but without significantly degrading the large usability and IDE-discoverability benefit that the remaining 12 chainable conversions below provide:
I would be strongly against removing these 12 conversions. |
Here are all the toX in ECMA262
Most of them are toString and toLocaleString. I do not think inside the current ECMA262 , we has a precedent of the toDataType() for naming convention, right? |
It seems like a good idea to create multiple slates of these |
"toString" and "toLocaleString" are an existing "toDataType" naming convention. |
Meeting 2024-05-23: At the upcoming June 2024 TC39 plenary meeting, we'll propose removing the following conversion methods:
We think that this is OK for the following reasons:
|
Can we remove all the functions that can be done via chaining? For example, |
We can do anything. :-). But my strong opinion is that we should NOT remove the Date=>ZDT 1-step conversion path. TL;DR - we want more developers going direct from PlainDate=>ZDT without going through PDT in the middle, to prevent DST bugs across the ecosystem. Details are below: First, some context: most date-time data in real-world business workflows (and therefore software) are dates (aka PlainDate), times (PlainTime), and "when exactly something happened" which can be timezone-irrelevant (Instant) or timezone-relevant (ZDT). PDT is less common than these 4. Furthermore, much of the usage of PDT-like data in computing is probably incorrectly ignoring the time zone and DST, because it is vulnerable to DST bugs. So in general I don't think we should be encouraging users to use PDT unless they specifically opt into using it. The "easy path" should nudge users to get a DST-safe result from a PlainDate value. WIth that context in mind, here's a few reasons to leave this conversion in place:
|
There is an implementation of the conclusion documented in #2848 (comment) available: here and here. |
Temporal contains 21 prototype methods that allow ergonomic conversion between one Temporal type and another type. Should we consider removing these methods below, and instead require callers to use
from
?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.
To understand the impact of this change, here's a representative use case that illustrates both subtractive and additive conversions: "For a particular date and time in my local time zone, what is the date in Tokyo?"
Here's the list of methods.
Temporal.Instant.prototype.toZonedDateTimeISO ( timeZone )
Temporal.Instant.prototype.toZonedDateTime ( item )
Temporal.PlainDate.prototype.toPlainDateTime ( [ temporalTime ] )
Temporal.PlainDate.prototype.toPlainMonthDay ( )
Temporal.PlainDate.prototype.toPlainYearMonth ( )
Temporal.PlainDate.prototype.toZonedDateTime ( item )
Temporal.PlainDateTime.prototype.toPlainDate ( )
Temporal.PlainDateTime.prototype.toPlainMonthDay ( )
Temporal.PlainDateTime.prototype.toPlainTime ( )
Temporal.PlainDateTime.prototype.toPlainYearMonth ( )
Temporal.PlainDateTime.prototype.toZonedDateTime ( temporalTimeZoneLike [ , options ] )
Temporal.PlainMonthDay.prototype.toPlainDate ( item )
Temporal.PlainTime.prototype.toPlainDateTime ( temporalDate )
Temporal.PlainTime.prototype.toZonedDateTime ( item )
Temporal.PlainYearMonth.prototype.toPlainDate ( item )
Temporal.ZonedDateTime.prototype.toInstant ( )
Temporal.ZonedDateTime.prototype.toPlainDate ( )
Temporal.ZonedDateTime.prototype.toPlainDateTime ( )
Temporal.ZonedDateTime.prototype.toPlainMonthDay ( )
Temporal.ZonedDateTime.prototype.toPlainTime ( )
Temporal.ZonedDateTime.prototype.toPlainYearMonth ( )
The text was updated successfully, but these errors were encountered: