-
Notifications
You must be signed in to change notification settings - Fork 157
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
static-functions Date.datePlus and Date.timePlus as JSON-friendly alternatives for classes CivilDate and CivilTime #82
Comments
No, it wouldn't be simpler; having primitive object types is much simpler than passing around strings that you have to implicitly know the type of. |
We should avoid creating new APIs that base everything on manipulating strings. "Stringly-typed" APIs are usually regarded as a code smell. As an example, the MDN page on types says:
Your examples above represent everything as strings. Years, months, days, hours, minutes, seconds, milliseconds, and nanoseconds are numbers and they should be represented as such. You've also presented a straw man argument regarding the JSON round trip. The current The rise of type checkers such as TypeScript and Flow have shown that developers want more control over types, not less. If you only use strings for dates/times, how do you get a type checker to verify that your code is correctly passing around dates? |
|
This is wildly false. I care about type errors (with or without a type system) at every single level - you continue to parrot the false premise that the only thing that matters is a webpage, and the JSON interaction between a webpage and a web server. These things are important but they are not the entirety of JavaScript, not by a long shot. Any argument framed by this false premise is not going to go far. |
@ljharb, web-projects are complicated beasts. does static-type-checking tell you whether or not whatever low-level library-code you're writing is actually useful, product-related code ... vs needless bikeshed/technical-debt? no it does not. what are common reasons why many web-projects fail? because of some silly type-error that wasn't caught because you weren't using TypeScript/Flow? of course not. they fail largely because programmers wasted their time writing low-level code in the dark (without code-coverage insight from end-to-end integration-tests) that ended up being technical debt. TypeScript/Flow only gives you a false sense of security that you're writing useful code - when you really don't have a clue, unless you have hard-data from integration-level test-coverage to back it up. |
@kaizhu256 yes, i happen to agree, which is why i want the ability to do stronger and clearer runtime operations by having first-class date/time primitives, instead of passing around opaque strings or object literals (which are a frequent cause of failures in web apps due to the lack of developer clarity involved). |
no we disagree.
and my conclusion comes from 6 years of analyzing javascript end-to-end code-coverage of integrated-systems. the typical code half-life for web-projects (where 50% of the code gets rewritten) ranges from 3-6 months for the the 1st year. after the 1st year, the half-life slows to 12-24 months, but only if the web-project is successful and passes integration/qa/deployment trials during the 1st year, which very few do. why do they fail in 1st year? because of integration-problems dealing with technical-debt. and there is surprisingly more of it from my code-coverage analysis, in javascrip-projects that extensively use class-based design-patterns ... vs ones derided as having "code-smell", because they avoided class-structures/meta-programming, and worked mostly with basic JSON-friendly data-structures, manipulated by static-functions. @gilmoreorless, in an ideal-world where all code you write is correct the 1st time around, then yea, Civil-classes and having structures makes sense. but that is not the reality for most javascript-based web-projects. they have incredible amounts of code-churn, and like i said, 50% or more it would be completely rewritten by the time it passes integration-trials dealing with end-to-end communication. as an example of real-world code-churn, code related to frontend-presentation is notoriously unstable. if you constantly had to rewrite the presentation-formats for date/time due to fluid design-specs, its more flexible and less technical-debty to due so with string-manipulations of date-strings/time-strings than with class-methods on CivilDate/CivilTime. |
Given we have advanced this proposal, with the five types described, to stage 2, I believe this issue can be closed. |
CivilDate and CivilTime are both classes that only have one method each (dealing with date and time arithmetic respectively). Would replacing these 2 classes and 2 methods with 2 static-functions (e.g. Date.datePlus and Date.timePlus that manipulate ISOStrings) be simpler?
it could solve the following issues for CivilDate and CivilTime:
here are the a/b code comparisons:
The text was updated successfully, but these errors were encountered: