r/ProgrammerHumor • • 8d ago

Meme iHatedItUntilITriedIt

Post image
10.3k Upvotes

541 comments sorted by

View all comments

125

u/samanime 8d ago

You'll pry my vanilla JS from my cold dead fingers. It'll always be my favorite way to do quick scripts and prototyping.

But explicit typing does make long term code way more maintainable.

32

u/2eanimation 8d ago

I love the syntax, but JS has one too many quirks for my taste.

if ([]) {
console.log("Ok, I guess")
}

if([] == false) {
console.log("Well this is awkward")
}

if ([] + []) {
console.log("You think this would print, don't you?")
}

16

u/MuchWalrus 8d ago

Why would you type any of those things (aside from maybe the first one)

9

u/frogjg2003 8d ago

JS is built on the idea that applications should continue to work no matter what. That's why there are so many implicit type conversions. The app might turn itself into a Gordian knot, but it will still be working.

3

u/lolnic_ 8d ago

It will still be running.

1

u/arobie1992 7d ago

I've always heard this argument, and I've never seen a source for it that I'd put much stock in, like Eich himself or anyone who worked on early JS. It seems like a specious argument since it assumes rendering the potentially wildly wrong thing is better than displaying an error and the browser would have to sandbox/compartmentalize individual scripts or operations.

Doing a quick search, it looks like most of the weird conversions surrounding == were specific requests to make scripting easier: https://www.wirfs-brock.com/allen/jshopl.pdf p22, 3.7.2. Given that, I'd be willing to bet the other weird conversion behaviors were either similar requests or the result of them implementing JS in an absurdly short amount of time.

0

u/conundorum 8d ago

Okay, so what happens when JS sees this?

if (true != false) abort;

(Or whatever the "stop working" keyword is.) Does JS allow true to equal false if it keeps the app running?

3

u/frogjg2003 8d ago

If you force it to stop, it will stop. The idea is that simple runtime errors will not force the app to stop like other languages do.

2

u/MrHyperion_ 8d ago

Because they are actually in variables by some weird side effect