433
submitted 1 year ago* (last edited 1 year ago) by kuneho@lemmy.world to c/programmer_humor@programming.dev

all 39 comments
sorted by: hot top controversial new old
[-] cupcakezealot 62 points 1 year ago

Programming Javascript is roughly the equivalent of hitting your head with a hammer or trying to uninstall McAfee.

[-] dohpaz42@lemmy.world 7 points 1 year ago

As if Javascript wasn’t complex enough, let’s introduce TypeScript and Coffescript and then write transpilers so we can convert said languages back into Javascript, which we could have done in the first place.

[-] traches@sh.itjust.works 30 points 1 year ago

Nobody uses coffeescript anymore, and typescript is there to make things easier not harder.

[-] devfuuu@lemmy.world 1 points 1 year ago

And all the new versions of all the above constantly being released. I'm so glad I don't use those languages anymore.

[-] excel@lemmy.megumin.org 1 points 1 year ago

These languages only exist because JS is so dumb in the first place

[-] towerful@programming.dev 24 points 1 year ago

Use stringly-typed everything, and always padStart your numbers.
Saves running into issues with numbers outside the 52-bit integer range.
And padding start means you don't have to worry about pesky sort functions.

Just don't do maths. Simple.

Maybe you could do a manual sort.
Provide a "captcha" prompt, and ask which comes first in the list... You know, to make sure the user is a human! And you get free sorting.

[-] dave@feddit.uk 37 points 1 year ago

Use stringly-typed everything

Instructions unclear. Now 1+2=12.

[-] LordTrychon@sh.itjust.works 16 points 1 year ago

I got 000001000002.

[-] kuneho@lemmy.world 21 points 1 year ago

Provide a "captcha" prompt, and ask which comes first in the list... You know, to make sure the user is a human! And you get free sorting.

I mean, this strangely is a compelling idea...

[-] RobotToaster@infosec.pub 7 points 1 year ago

Just don’t do maths. Simple.

That's a good rule for life in general, really.

[-] oessessnex@programming.dev 3 points 1 year ago

Turn JavaScript into Bash with these easy steps...

[-] Ategon@programming.dev 19 points 1 year ago* (last edited 1 year ago)

Note if you put the image link in the url bar of the post rather than the body it lets people see it while scrolling (url + title can be edited so you can edit it to do that still if you want)

[-] kuneho@lemmy.world 7 points 1 year ago

thanks!

using 3rd party client (and first "image post" I've made on this platform) and wasn't sure how image post should be made.

[-] Grass@geddit.social 7 points 1 year ago

Is there even any case where you would want this?

[-] fuck_u_spez@lemmy.fmhy.ml 6 points 1 year ago

I couldn't believe it, tried it out, what the actual heck? I mean I get all these weird string vs number comparison but sorting actual numbers and this comes out? What kind of drugs were the designers of javascript (or at least this function) on... Who thought it was a good idea to sort numbers lexicographically??

[-] Kerb@discuss.tchncs.de 5 points 1 year ago

Probably meth or cocaine, considering js was written by a single person in 10 days

[-] valourvalkyria@lemmy.world 1 points 1 year ago

Iirc Array.sort requires you to pass a function in, or it casts into strings and sort them.

That way they get to reuse the code for sorting strings!

[-] VonReposti@feddit.dk 5 points 1 year ago

Well, 3 out of 5 correct ain't bad. With some more trial runs we might get this thing nailed!

[-] CanadaPlus@lemmy.sdf.org 3 points 1 year ago

So, I think just yesterday or the day before someone on here was saying we shouldn't make fun of JavaScript anymore.

[-] solarzones@programming.dev 3 points 1 year ago

JavaScript knows my truest fears too LOL

[-] Aurenkin@sh.itjust.works 2 points 1 year ago

JavaScript: You chose this path, now I have a surprise for you

[-] roboter5123@lemmy.world 1 points 1 year ago

Deploying surprise in 3, 2... Hold up for a seco d that wasn suppossed to happen.

[-] heartlessevil@lemmy.one 2 points 1 year ago

I don't think JS works that way

[-] rikudou@lemmings.world 32 points 1 year ago
[-] Quasari@programming.dev 21 points 1 year ago* (last edited 1 year ago)

Array.prototype.sort if no callback is passed to it will coerce non-undefined elements to strings when sorting. It does do that.

To sort numbers passing a function like (a, b) => a - b is good enough.

[-] stratoscaster@lemmy.zip 17 points 1 year ago

Fuck JS is stupid.

Source: use JS regularly

[-] Freethewhat@lemmy.world 1 points 1 year ago

Ugh, I just ran into this in Terraform. Why is this a thing?

[-] Swiggles 8 points 1 year ago

It's just sorted alphabetically (technically it is the UTF16 code order). To be fair it's a sane default for most use cases. In JS case you can define a very simple callback to change the behavior to numeric sorting (a,b => a<b). Many other sorters provide a flag instead, but numeric sorting is seldom the default as it is not as useful most of the time in weakly typed languages.

[-] excel@lemmy.megumin.org 2 points 1 year ago

weakly typed languages

Well, looks like we found the problem right there

this post was submitted on 07 Jul 2023
433 points (100.0% liked)

Programmer Humor

19623 readers
1 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS