-
Notifications
You must be signed in to change notification settings - Fork 152
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
[Proposal] Temporal.Something(...args) instead of Temporal.Something.from(...args) #755
Comments
Thanks for the feedback and for proposing a change! I believe this has been discussed at a fairly early stage in the proposal long before I was involved, but maybe someone else can weigh in, if not then I will try to dig up the discussion on Monday. |
Here are some issues that contain previous discussion on this topic:
The guiding principle so far has been, constructors are a "lower-level" way to create Temporal objects, that accept numeric-only ISO-calendar-only values, and do not take options; corresponding exactly to the object's internal data model. |
Thanks for the background @ptomato! Looking through the arguments put forth in those issues, I think the above proposal still stands. While I don't want to take sides on the Re: internal data models, although I understand the appeal of having method signatures match internal data models, I think that amounts to a 'leaky abstraction' when those data models are not the most useful ones for the end user. If anything, the positional-arg methods that match the internal data models could be included as static factory methods for the rare cases where users prefer them - they could look something like |
During the discussions when we iterated on the API based on this feedback, we decided to stay with the status quo. The split between low-level constructors and high-level from() has been a core design principle of Temporal since quite early on, and although other options seem just as valid, this is the one that we felt works for Temporal. |
.from(...args)
increases character count without (much) added specificity, makes the method signatures less discoverable in IDEs (sinceTemporal.Something
will surface a suggestion forTemporal.Something()
), and makes it hard to search for the documentation in search engines (e.g. a search forTemporal DateTime from
could return results forTemporal DateTime
, ignoring 'from').Instead, why not allow constructors, with or without
new
, to take the arguments that.from
takes?For example, the set of signatures:
could become
Similarly:
could become
This pattern could be applied to most of the
Temporal.*
member objects, potentially increasing readability, discoverability, and brevity.I've mentioned this in passing in #751 and #743, but thought it deserved its own issue. Let me know if there is a better forum for this suggestion, or if this has already been discussed.
The text was updated successfully, but these errors were encountered: