-
Notifications
You must be signed in to change notification settings - Fork 159
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
Brevity of API #743
Comments
|
I'm assuming "now" returns a distinct object, is it a method? Returning distinct objects is not a reason to use functions. |
It very much is a reason for that. Put another way, using an accessor property to return distinct objects every time is exceedingly confusing and strange, so the burden of proof is on that scenario imo.
|
High character counts for simple tasks is also my main gripe after skimming through the cookbook, take for example the suggested way of converting from old const absolute = Temporal.Absolute.fromEpochMilliseconds(legacyDate.getTime()); Thats more than 50 characters of Temporal for what's certainly going to be one of the most common tasks in the initial years of using this API. Intuitively I'd expect it to just be |
I think that's a pattern we've consciously moved away from, so it won't be the best idea.
Precisely what @ljharb said.
The champions group (and I personally) share(s) the same values. If you have any specific proposals, I'd love to hear them and consider changing them. |
@pirate if you have specific suggestions for any of these methods, we'd gladly consider them. Besides, I don't specifically agree that character count should be given a large emphasis in API design? Brief APIs are great, but not at the cost of clarity, especially in 2020 when most developers use an editor with code completion functionality. |
@ryzokuken why not allow |
|
Specifically on the Absolute object, I'd remove the Epoch word, as it should be implied by it being an Absolute datetime. To shorten it even further, you could always use something like |
For constructors, how about accepting named args, instead of having many For Temporal.Absolute(source: bigint | Date | {seconds: number} | {milliseconds: number} | {nanoseconds: number}) This would have the added advantage of letting APIs respond with things like |
Thanks for the feedback, by the way! I think there are a couple of takeaways here, the main one being that brevity is appreciated 😄 One thing not mentioned yet so far in the thread is that Temporal doesn't require you to use the types with There is more discussion on methods vs. properties at #724, you might want to subscribe to that discussion as well. |
@ryzokuken In the case of a module as fundamental as Temporal, I disagree. The most important benefit of shorthands (in both natural and constructed languages) is not that they are easier to write, but that—given the expectation of some prior knowledge or familiarity with a subject—they are easier to read. Consider:
The first contains far more information, and is thus clearer to people with no prior knowledge. But to those with prior knowledge, it's profoundly burdensome. The latter is not only just as clear, but short enough to be apprehended at a glance (arguably below the level of conscious thought). The question is whether the audience can be reasonably expected to seek out this knowledge if they don't have it. If not, then the audience must instead devote their finite attentional/cognitive resources to translating a long string of words into an idea they already possess. I would argue that converting a Date to a Temporal is definitely something JS developers can be expected to internalize. Clarity over convenience may be a best practice in general (i.e., for specialized, obscure, or third-party libraries without wide usage), but applied to core modules like Temporal, they will erode the utility and readability of the language in the long-term. |
@rlue I whole-heartedly agree with your analogy. That why I said that I do sympathize with the need for a more brief API surface. I did however mention that it should not happen at the cost of clarity, which should infact result in a poor reading experience. |
Many of the comments above deal with ergonomics & brevity for constructing I also opened #750 to track whether |
This change has landed.
#751 has landed too: In addition, a big brevity improvement added recently is the ability to use strings instead of Temporal objects as arguments to Temporal methods. For example: |
"More brevity" was by far the most common feedback that we got and I think we've addressed it, even if not in the exact ways suggested here, with the changes Justin mentioned above and others. I hope that it feels less verbose as a whole now! Closing this. |
Maybe it's worth considering this API as a part of standard library rather than default part of language? Like in c++, there is no problem to #include , same could be here Personally I very much doubt it would be a pleasant experience to type dozens characters for basic operations. Not only in IDE, but also in REPLs and so. |
@stiff thanks for the suggestion, there have been discussions regarding built-in modules at https://github.com/tc39/proposal-built-in-modules. That said, I feel that built-in modules won't be adopted for quite some time and it's unfair to delay Temporal on it. That said, note that something like |
I'm a lazy programmer, and a crap typist. As such I prefer a bit more brevity in my code. Obviously, these are just my opinions.
Temporal.<whatever>
is already long enough, I think avoiding the need for the new keyword would be nice (I know there are those who would prefer not using thenew
keyword at all in JS, and some make good arguments)Temporal.now.absolute()
, if the method is never intended to accept parameters, why not simply make it a read-only property ?This proposal is a long time coming, if you'll excuse the pun.
Hope it reaches browsers soon!
Thanks for all your hard work!
The text was updated successfully, but these errors were encountered: