this post was submitted on 24 Nov 2025
558 points (89.2% liked)

Programmer Humor

27500 readers
1487 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 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] FishFace@piefed.social 2 points 2 days ago (1 children)

I mean how can you define a sensible way to subtract Infinity from an array, or add an object to a string?

TypeError.

There are also various sensible ways, for example if you have an array of floats, subtracting Infinity from the array could result in an array of the same length as the original, with each value being negative Infinity. But in general inhomogeneous types should not be addable without careful thought to create a type system which is consistent and coherent. That is exactly what JavaScript did not do.

It doesn't "handle bad code gracefully"; it handles it in a way that's hard to reason about and hence hard to work with.

The way JavaScript defines it is predictable

You literally just failed to predict it, so I don't think there's any point continuing this conversation.

[–] hperrin@lemmy.ca 1 points 2 days ago* (last edited 2 days ago) (1 children)

Ok, except I did predict it. It turns them both into strings and gives you “12”. I checked it. But I didn’t mean predictable as in, you inherently know what it’s going to do, I meant predictable as in, it will follow the same basic rules in each circumstance.

So, should web pages be prone to crashing if everything isn’t perfect? I don’t know if you remember XHTML, but that was basically what happened with that. You have a “div” within a “p”? Page crashed. You have an unclosed “span”? Page crashed. XHTML was abandoned because is constantly broke the web.

Web technologies are supposed to be resilient, so throwing TypeError is the last resort for something that absolutely cannot work, like trying to add to a Symbol. Since nothing from the user is ever a Symbol (there’s no input that can give it, and it can’t be stored in JSON), it’s acceptable to throw a TypeError there.

JavaScript is meant to be fast and resilient. Its type conversions make sense when you consider those goals.

[–] FishFace@piefed.social 1 points 1 day ago (1 children)

Getting it on the third guess is not the brag you seem to think, and I'm still not engaging with you on the rest.

[–] hperrin@lemmy.ca 0 points 1 day ago

I’m sorry I didn’t think it was [1,2].