-
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
revisit: Dealing with JSON.stringify() #80
Comments
That is pretty much it, except that
Edit (2018-09-20): We have reversed that. The geographic IANA name has become optional, but will be there if known. |
what would be the roundtrip/revive solution? would it follow Date's behavior and have the constructors accept a JSON-string as a first-argument? // copy Date-like roundtrip behavior?
date1 === new Date(JSON.parse(JSON.stringify(date1));
civilDate1 === new CivilDate(JSON.parse(JSON.stringify(civilDate1));
civilTime1 === new CivilTime(JSON.parse(JSON.stringify(civilTime1));
civilDateTime1 === new CivilDateTime(JSON.parse(JSON.stringify(civilDateTime1));
instant1 === new Instant(JSON.parse(JSON.stringify(instant1));
zonedInstant1 === new ZonedInstant(JSON.parse(JSON.stringify(zonedInstant1)); |
@kaizhu256 no, the constructors would only be:
However there are |
why not? are there technical reasons? this seems to make CivilObjects less easy-to-use than Date for web-developers dealing with product-integration. |
this is a step-backwards from Date in terms of ease-of-use. you do realize that unlike other languages, most real-world use-cases for data-structures in javascript product-development revolve around JSON serialization/revival? |
from a use-case perspective, javascript-users are far more likely to construct these CivilObjects from JSON/url input-strings (via server-http-requests, dom-element-data-attributes, client-ajax-responses) than through arguments-based constructors. you're calling for a design that ignores the common-case scenario in web-development. |
That's not actually the case, and it's a very bold claim backed by no evidence - and it doesn't match Airbnb's use case, as an example. Similarly, "ease of use", while important, is far less important than "correct" - Date is not correct by many metrics, however Temporal will be. |
So what you are really saying is that:
CivilDate.fromString(JSON.stringify(date))
is much harder to write than
new CivilDate(JSON.stringify(date))
???
… On 19 Sep 2018, at 22:31, Jordan Harband ***@***.***> wrote:
most real-world use-cases for data-structures in javascript product-development revolve around JSON serialization/revival?
That's not actually the case, and it's a very bold claim backed by no evidence - and it doesn't match Airbnb's use case, as an example.
Similarly, "ease of use", while important, is far less important than "correct" - Date is not correct by many metrics, however Temporal will be.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@pipobscure. yes. i'm saying your arguments-based constructors are a minority use-case, when most web-based inputs are string-based. @ljharb, i don't believe its a strong-statement. most of javascript programming i've experienced in industry revolves around string-manipulation of dom/url/request/response data/properties (and then directly passing manipulated-strings back to client/server/db/dom). class-instantiation of things like CivilObjects are for mostly transient-objects, that are quickly destroyed, once the client <-> server <-> db request/response is done. alot of these real-world tasks could be acoomplished more efficiently, with just static-functions that manipulate strings like (#82) and (#53) |
In order to foster a productive discussion, I suggest we focus on explaining the design principles of this proposal vs. what @kaizhu256 asked for. For example, someone involved in the proposal could comment about the reasons/benefits/principles behind choosing the static |
Ok,
The most frequent task in creating software of any kind is actually NOT writing code, but rather reading it. Therefore being explicit is much more valuable. Now if one is insistent on always using constructors, the conversation to be had isn't so much about the stringify round-trip (which is important), but rather about whether the use of constructors for that purpose is a good thing™️. I would go so far as to claim that but first things last: while the serialisation/deserialisation round-trip is a quite important use-case, it's by no means the dominant one. It may be the dominant one in a pure web-browser world, but even that premise is arguable. From your reference to #82 & #53 I deduce a clear preference for basically doing everything in the world with just strings (I'm exaggerating obviously); If that's the case, there is nothing to prevent you to wrap temporal in a very thin layer to do that for you; I'll even voluteer to write you that wrapper to add last but not least: I truly do not comprehend your argument that You say that "arguments-based constructors are a minority use-case", and I'm saying that "multivariant constructors are an anti-pattern" and "your use-case is just as easy using what we propose, just not using a constructor". What is it that eludes me? |
why are if you want to say its an anti-pattern, can you give examples in a javascript-context (rather than a c#/java/c++ context) on why its bad? |
I'll repeat the question: what am I missing; but ok here we go: First off: Multivariant Constructor Anti-PatternClarity / ExplicitnessFor one thing multivariant constructors are bad because it is hard to know what kinds of arguments you are expecting. Given that JS is dynamically typed, this can become problematic because mistyped arguments may still be acceptable, but for another variant of the constructor. If one instead uses explicit static functions, that woe goes away. The Variant Variability causes trouble with dynamic typesOf course the unexpected types may well lead to a different constructor variant being used producing valid objects with unexpected values. Examples:
These results (using v8 6.7.288.46) are utterly unintuitive for non-literal arguments. Take these instead:
beyond being just explicit, this makes it impossible to get corrupted data from bad arguments. These are exactly the kinds of bugs that are pervasive. Multivariant constructors aren't the only cause of this of course; at heart it's part due to the way JS does type-coercion. But multivariant constructors make the issue worse. In other words, especially in a dynamically typed language such as JavaScript being explicit is incredibly important. And that's before going into the fact that code-reading is actually much more pervasive than code-writing; as such being explicit is incredibly important and help people actually understand code better. Second: Stringly-Typed functionsserialise/deserialise overheadEvery action such as
Rarely will any such calculation be used in isolation. As a simple example let's look at the following:
If you take the steps here, they'll be:
You will note that steps 3 & 4 are entirely superfluous. Now we could of course then just add a As you mentioned yourself in #82, MDN warns against stringly typing for complex data. You then asserted that date-string is not complex-data. I consider that statement to be false. Of course dates and times are not the most complex data there is, but they are nevertheless complex data; arguable more complex than comma-separated lists. So I'll refer you back to the arguments made by the MDN page you cited with the presumption that dates/times are actually complex data. All of those will hold and give you further arguments for why Lastly: I consider the claim "javascript is not a low-level, general-purpose programming-language like c#/java/c++." highly outdated. It may have held true in 1995 when it was created as a specialty language for web-browsers, but it hasn't been true since 1997 when Rhino was introduced as JS on the backend; no matter it's definitely become incorrect since 2009 with the advent of nodejs. It may not be low-level if you take that to mean compiled directly to processor instructions then yeah. But as soon as you involve a runtime interpreter (such as a JVM or .NET) this becomes questionable. But it definitely has become general-purpose and as low-level as Java/C# and the like. JS is currently being used to drive web-sites and web-servers; iot-microservices and iot-devices; shells and shell-scripts. The language is evolving to accomodate many, many more uses than "your grand-dads-javascript" and this proposal should be suited to all of them. |
@pipobscure thank you very much for responding to @kaizhu256 |
that's exactly why we have javascript-fatigue now. tc39 carried that paradigm too far, and the result is chaos. this temporal-proposal is the kind of radical-change (rather than iteratively enhancing Date) that makes people like me feel tc39 has learned nothing from its past mistakes. |
Date is inherently broken; the mistake would be iterating on it. |
then can you demonstrate how this proposal is less-broken than Date? like filling out the (https://github.com/tc39/proposal-temporal#scenario-based-examples) section in the README with A/B code-examples, showing web-developers how CivilObjects would be easier-to-use than Date. |
Conclusion: "roundtrip/revive solution" is I suggest other issues to be created to treat/discuss other topics. For example, "section in the README with A/B code-examples", @kaizhu256 I think that's indeed great to have. Could you go ahead and create a separate issue? |
closing this issue per request. |
#77 is vague.
looking at README.md, these would be the results under JSON.stringify? does the behavior essentially copy toString()?
The text was updated successfully, but these errors were encountered: