new Date("wtf") (jsdate.wtf)
from Sheldan@programming.dev to programming@programming.dev on 11 Jul 21:37
https://programming.dev/post/33754840

#programming

threaded - newest

bleistift2@sopuli.xyz on 11 Jul 21:48 next collapse

I am a frontend dev. JavaScript (well, TypeScript) is my bread and butter. Even knowing its quirks I never would have thought how inconsistent Date actually is. I encourage everyone to try this quiz.

This is what JavaScript haters should bring forth, not 0.1 + 0.2 !== 0.3!

Tanoh@lemmy.world on 11 Jul 22:10 next collapse

There is a reason almost everyone use some Date lib, like Luxon and not the built in. And well, having a horrible built in lib that they can’t change due to legacy code breaking is nothing really new or unique to JS.

bleistift2@sopuli.xyz on 12 Jul 23:00 collapse

The built-in lib is fine for basic stuff unless you do some crazy shit like expecting “2” to parse as a valid date.

Tanoh@lemmy.world on 13 Jul 00:05 collapse

For very basic things maybe, but it has a lot of other weird problems and restrictions. Mutability, no real timezone support, very limited arithmetic, to name a few. As soon as you move beyond the very basic, you want someting more robust.

Hotzilla@sopuli.xyz on 12 Jul 05:40 next collapse

Floating point rounding issues are basic comp science issues. Hopefully nobody thinks that those are JavaScript quirks.

bleistift2@sopuli.xyz on 12 Jul 13:54 collapse

Unfortunately, people do.

dalekcaan@feddit.nl on 12 Jul 22:50 collapse

Or the ones where people point out how inconsistent JS is with adding strings to numbers.

Yeah, maybe don’t do arithmetic on numbers as strings?

anton@lemmy.blahaj.zone on 11 Jul 22:17 next collapse

Great quiz. It teaches you the rules while training you to expect the unexpected, even in the rare cases that the rules are applied consistently.
I got exactly half the questions right.

salmoura@lemmy.eco.br on 11 Jul 22:35 collapse

I scored 8/28 on jsdate.wtf and all I got was this lousy text to share on social media.

don't tap for spoilers

The sequence of questions about new Date(“0”), new Date(“1”), and new Date(“2”) got me good.

bamboo@lemmy.blahaj.zone on 11 Jul 23:08 next collapse

That was so funny, I had to pause taking the quiz I was laughing so hard at question 9. The snark in the explanations is fantastic.

mesamunefire@piefed.social on 11 Jul 23:56 collapse

Same. I think I got one on accident too.

mesamunefire@piefed.social on 11 Jul 23:56 next collapse

I did not do well:

"I scored 9/28 on https://jsdate.wtf and all I got was this lousy text to share on social media."

Ive been a dev for a long time. Im glad im not doing javascript all that much anymore.

DrWorm@piefed.social on 12 Jul 01:01 next collapse

The quirks in this quiz aren’t even universal, and vary based on which browser you’re using. See the table at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse#non-standard_date_strings

Also I got 13/28 😑

SirQuack@feddit.nl on 13 Jul 15:44 collapse

7/28 and I program in JS and typescript daily…

Macallan@lemmy.world on 12 Jul 01:07 next collapse

I got a 4/28 and got told I would have scored higher if I guessed at random. Ouch. (I am not a dev)

Ephera@lemmy.ml on 12 Jul 07:24 collapse

I mean, for what it’s worth, I’m a seasoned dev and just did a run where I tried to answer everything as it makes sense to me (which is “throws an error” or “invalid date” for all of them) and I also got a score of 4/28.

…and two of those points were given to me, because the quiz interpreted my answer differently than I meant it.

In other words, this quiz exists to highlight that JavaScript’s Date functions make no sense.

ragingHungryPanda@lemmy.zip on 12 Jul 01:08 next collapse

I got 10/28, but I was crying after the 7th question

LPThinker@lemmy.world on 12 Jul 01:19 next collapse

Thank god Temporal is finally in Stage 3, and already rolled out in Firefox. I can’t wait to be done with JS’s Date forever.

hperrin@lemmy.ca on 12 Jul 01:50 next collapse

I scored 13/28 on jsdate.wtf and all I got was this lousy text to share on social media.

Oof. I’ve been a JS dev since 1998.

tleb@lemmy.ca on 12 Jul 01:59 next collapse

I scored 17/28 on jsdate.wtf and all I got was this lousy text to share on social media.

Idk anything about Date but got pretty far with intuition of JS whackiness

lunarul@lemmy.world on 12 Jul 04:05 next collapse

If you’re not very familiar with JS, watch the Wat talk before taking the quiz to know what to expect from this wonderful language.

Lemminary@lemmy.world on 12 Jul 06:00 collapse

And then promptly get yourself familiar with how the language actually works. github.com/getify/You-Dont-Know-JS

People who complain about JS often assume it has features of other languages and fail to realize it has its own architecture and winding history.

atzanteol@sh.itjust.works on 12 Jul 04:51 next collapse

Nobody understands JavaScript. It’s the quantum mechanics of the software world.

fubarx@lemmy.world on 12 Jul 06:03 next collapse

9/28. WTF’ing through 90% of the questions.

tatterdemalion@programming.dev on 12 Jul 06:10 next collapse

Can we start a new web with a better language/platform already?

FooBarrington@lemmy.world on 12 Jul 07:05 next collapse

Why? Why not improve JS (e.g. with Temporal), especially given how excellent Typescript is?

tatterdemalion@programming.dev on 12 Jul 07:26 next collapse

JS is a lost cause.

FooBarrington@lemmy.world on 12 Jul 07:33 collapse

How? It’s easy not to run into the common issues by using TS. What’s so bad about it that we should throw away the existing ecosystem?

Please give arguments instead of platitudes.

bleistift2@sopuli.xyz on 12 Jul 14:01 collapse

You don’t need to use TS to avoid common issues. If you add an empty object to an empty array and expect a meaningful result, the problem sits in front of the keyboard.

FooBarrington@lemmy.world on 12 Jul 14:23 collapse

Sure, discipline can prevent some errors. But it’s always possible to run into wrong type assumptions, and I’d say type coercion and null/undefined access make up a fairly large percentage of non-logic errors. You can entirely prevent those using Typescript, which is why it’s so useful.

Static type analysis is always a good idea if you’re writing more than a couple lines. IMO Python is the worst offender with its kwargs etc. - discoverability and testability is just so bad if you’re following common Python idioms.

Sheldan@programming.dev on 12 Jul 13:04 collapse

I wouldn’t call typescript excellent, if I did it would be on a very low standard.

FooBarrington@lemmy.world on 12 Jul 13:44 collapse

It unquestionably is excellent. Can you name another language in common use with a type system that’s close to the expressiveness of Typescript?

expr@programming.dev on 13 Jul 15:19 collapse

Let’s not get ahead of ourselves. Typescript has a decent type system, but it’s hardly state of the art. It’s impressive how they’ve managed to mostly corral JavaScript into something much more sane, but at the end of the day it still suffers greatly from the limitations of JavaScript. They’ve essentially retrofitted some type theory onto JavaScript to make it possible to express JavaScript nonsense in the type system, but there’s plenty of things that would have been designed differently had they been making something from scratch. Not to mention that the type system is unsound by design, which by itself puts it behind languages designed from the ground up to have sound type systems.

There’s many, many things missing from the type system, like higher-kinded types, type-driven deriving/codegen, generalized algebraic data types (aka GADTs), type families (and relatedly, associated types), existentially-quantified types, and much more.

FizzyOrange@programming.dev on 12 Jul 07:52 next collapse

Google tried to do that with Dart, and failed. In fairness Dart 1 was much worse than Dart 2… So maybe that was a good thing because there’s no way they’d have been able to improve Dart as much as they have if it was part of the web.

For dates there finally is something better anyway: developer.mozilla.org/en-US/docs/Web/…/Temporal

sudo_halt@lemmygrad.ml on 13 Jul 00:26 collapse

Dart is fucking amazing and it compiles to native code, transpiles to JS (with some restrictions on concurrency because of web workers) and also supports WASM.

Really if you want to write async and stream based code Dart is very good

syklemil@discuss.tchncs.de on 12 Jul 08:05 collapse

There’s wasm if you need to target browsers.

festus@lemmy.ca on 12 Jul 14:44 collapse

Yes and no. Wasm has no “standard library” so if you wanted to use Dates, your wasm would need to have its own implemation bundled for when the user visits the page. Ditto for everything else including string support! As you can imagine having to ship all this basic functionality can bloat the wasm and slow page loads.

You also can’t fully escape JS, as the only way wasm can interact with the page & browser are through the JS functions you write and make available to your wasm. I suppose you could take advantage of this to not have to ship your own standard library & use the JS Date implementation, but at that point why not just use JS?

Wasm has strengths but it’s not suitable for replacing JS for everyday websites.

Xylight@lemdro.id on 12 Jul 06:15 next collapse

I don’t like calling myself a JS/TS dev but my biggest project that I currently work on is written in it, so I had to try it.

16/28. I mean it’s incredible how I can throw a diabolical amount of variations of formatting at it and somehow get valid dates.

schnurrito@discuss.tchncs.de on 12 Jul 06:31 next collapse

7/28. Of course no one would ever do most of those things, they are interesting to think about but with little practical use.

FizzyOrange@programming.dev on 12 Jul 07:50 next collapse

Ha this is even worse than I could have imagined!

MTK@lemmy.world on 12 Jul 08:20 next collapse

This is just a good reminder of human nature to make bad choices (using JS) and stick with them forever.

Sorse@discuss.tchncs.de on 12 Jul 08:31 next collapse

12/28

Surprised that I got this score when I only know python

mr_satan@lemmy.zip on 12 Jul 09:07 next collapse

I scored 10/28 on jsdate.wtf and all I got was this lousy text to share on social media.

brb@sh.itjust.works on 12 Jul 10:22 next collapse

Except for some reason “2” is interpreted as a month, and the year is set to 2001.

Aight I’m out

humanspiral@lemmy.ca on 12 Jul 23:48 collapse

“12.1” is interpreted as the date December 1st, and as before for dates with no year the default is 2001 because of course.

it gets better and more coherent the deeper you go :P

thenextguy@lemmy.world on 12 Jul 13:33 next collapse

Alright, enough making fun of languages that suck…let’s talk about JavaScript.

www.destroyallsoftware.com/talks/wat

catalyst@lemmy.world on 12 Jul 14:53 next collapse

It only took one question for me to start wanting to flip tables.

humanspiral@lemmy.ca on 12 Jul 23:49 next collapse

Can we sue Oracle back for any of this?

BatmanAoD@programming.dev on 13 Jul 02:27 collapse

Oracle? Oracle owns Java, not JavaScript.

Edit: mea culpa! Sun owned both!

humanspiral@lemmy.ca on 13 Jul 02:51 collapse

They ended up with Javascript trademark (afaik, because the name was too close to Java) too. Sued node.js over something related.

BatmanAoD@programming.dev on 13 Jul 06:12 collapse

Apparently the JS name was selected and announced in partnership with Sun from the very beginning, and Sun had the copyright over both Java and JapaScript up until the acquisition by Oracle. I had no idea, but that makes perfect sense.

humanspiral@lemmy.ca on 13 Jul 10:50 collapse

Sun, afaiu, was part of a large committee on js without any particular leadership. They got the committee to agree to giving it trademark by complaining/threatening that the name was too close to java. Sun got trademark 4 years after Netscape started support for js. ECMAscript was mostly the same committee without SUN ownership/trademark.

badbytes@lemmy.world on 13 Jul 01:14 collapse

Not the best with js, but that quiz was fun.