-
Notifications
You must be signed in to change notification settings - Fork 153
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
Consider removing toString and valueOf methods #74
Comments
Ok. Questions:
Also I really dislike having both |
toString is also frequently used for debugging - not just for implicit coercions. I would not be comfortable with repeating the (necessary and understandable yet still) highly unergonomic situation of Symbol’s undebuggability, nor with “[object Object]”. |
@ljharb Could you give more information on what you would like to see from debugging Temporal objects? (Presumably the alternative is, e.g., |
An ISO timestamp would be sufficient, although also including the type would be excellent. |
@ljharb I mean, what sort of debugging flows are you thinking about? Overall, |
@pipobscure I don't have a strong preference on either of those questions; the names I was suggesting were just an early draft suggestion. What I'm trying to get at is, if you use those special names, special things will happen, and I'm not sure if that's what we want. |
True, things like https://npmjs.com/object-inspect combine the toString output with type output; but it’d be nice to not have to jump through hoops. |
@ljharb Is there anything you could tell me about your debugging flow that creates this requirement? |
I’m not sure what explanation you’re looking for - i have a value (in a debugger or a logging statement or an exception message or a test framework assertion), instanceof isn’t reliable/cross realm, and i want the quickest and most generic path to a useful string that describes the value. |
Almost every platform you can use JS on does deeper introspection of a value than just I'm personally very much for dropping |
I don't have a strong opinion on |
|
I suppose equality will work, but comparison is still broken. |
What do you mean? If we remove valueOf, the meaning of < goes from comparing ns to throwing a TypeError, right? Then, we would add comparison methods. |
I would actually vote for removing
That to me make |
In #76 I changed
Comments Please!!! |
-1 for toString giving somethign of the form [object Type X]. That is unprecedented in JS and not a good pattern in general. I think it should just do what it does for every other type, and give a useful string representation, e.g. ISO-String. |
How about
"calendar date", "ordinal date", "week date" are concepts defined by the specification.
It's wordy though. |
@ljqx the reason I dislike the toISO*** method names is because there is a suggestion of being ISO complete. This comes back to bite us when we define Of course we could go whole hog on the pairs:
The question is whether there is any real benefit; also would string formatting not be better left to something other such as |
The conclusion I draw from the discussion so far is:
(Please up/down - vote to indicate whether my summary is accurate or if it's premature) |
There can be a pretty big difference between Use of relational operators to compare at least date-times with each other and dates with each other might be nice enough to justify non-abrupt completions from cross-type comparisons (even though those results would be meaningless), which in concrete terms would probably look like |
+1 to #74 (comment) re valueOf and toString, except:
|
I agree regarding .value although I sincerely hate loooong names like nanosecondsSinceUnixEpochWithoutLeapSeconds
Regarding JSON not round-tripping, I know of no way to make this roundtrip without changing JSON which is a no-go to me. And this behaviour is much better than throwing. I consider the String behaviour better than throwing like BigInt, because you only need to deal with reviving if the value is what you are actually interested in. If you are interested in some other part of the tree, you can parse/modify/stringify without having to know about the temporal thing in there. So in terms of ergonomics I think it’s a winner.
… On 4 Aug 2018, at 22:46, Daniel Ehrenberg ***@***.***> wrote:
+1 to #74 (comment) re valueOf and toString, except:
value is probably worth another round of bikeshedding (shouldn't this name somehow say what it represents?)
I am not sure if we want to add another toJSON method by default which doesn't round-trip; I am not sure if Date is a model we want to repeat
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Well, I think we should come to a common conclusion among Temporal and BigInt re the throwing issue. BigInt could also serialize |
throwing could break loggers that rely on JSON.stringify/toString (which until now, have assumed vanilla objects/builtins/primitives won't throw), like this real-world example: /*
* json-logging example from
* https://github.com/kaizhu256/node-utility2/blob/2018.6.21/lib.utility2.js#L4784
*/
// debug middlewareForwardProxy
console.error('serverLog - ' + JSON.stringify({
time: new Date(options.timeStart).toISOString(),
type: 'middlewareForwardProxyResponse',
method: options.method,
url: options.url,
statusCode: response.statusCode | 0,
timeElapsed: Date.now() - options.timeStart,
// extra
headers: options.headers
})); |
I raised the possibility of throwing from |
Summary:
Can we take this as sort-of agreed? (I'm about to start updating things in advance of the TC39 meeting to reflect the current state) |
This is agreed. Going to note this when I present. |
This is the part where I don't really agree--I'd prefer we throw an exception or generate |
|
@ljharb I'm not sure what you mean, or how that relates to what we should do here. |
You said "I'd prefer we throw an exception or generate { }", and that you didn't want to follow Date because it does not round trip, but "generate { }" does not round trip either. |
In other words, if round tripping is a requirement, then throwing an exception is the only option. However, I don't think there's consensus that round tripping is a requirement. |
I see, well, I'd say it's better to either fail somewhat loudly/thorougly or be really correct; muddling through makes me a bit worried. In particular, about JSON, we discussed this issue with respect to Map and Set, and came to the conclusion that they should continue to return |
The difference is that On the contrary, the temporal objects all constiture single discreet values, and the objects come with a static function ( In addition, the readable ISO string format actually has data value and works transparently, making multiple round-trips painless. In my opinion this is the one thing that |
agree with @pipobscure. non-nested data-structures should follow Date's JSON behavior for ease-of-integration with JSON and consistency. i'm skeptical general-purpose tooling to auto-revive JSON data-structures without application-context will ever be viable. its naive thinking. javascript product development will always require user-intervention in the JSON.parse/revival step. the best tradeoff is too accept that and focus at least on making JSON.stringify automatic. |
OK, I take it you all disagree with the decision of BigInt to not use toString as its toJSON, then? |
@littledan most definitely. It makes working with All it did is require me to have a mini library:
used like
just making it needlessly painful for no benefit. It's not like throwing on |
OK, in this case, I think we should come up with a common decision for both. We were pretty explicit about this decision for BigInt, but it could be revisited without (probably) breaking compatibility. |
obsolete. Conclusion: no |
Various parts of JS call these operations implicitly, when converting to a Number or String. Enabling such implicit conversions doesn't mesh well with the strong typing of this proposal. I am wondering, would it make sense to expose this functionality under other names, which don't enable coercion, such as toISOString and nanosecondsSinceEpoch? It would make some code more wordy, but the upside would be less risk of errors.
The text was updated successfully, but these errors were encountered: