this post was submitted on 04 Jun 2025
1022 points (98.6% liked)

Programmer Humor

23861 readers
2989 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
[–] grue@lemmy.world 27 points 2 days ago* (last edited 2 days ago) (3 children)

It is 'comprehensible' in the sense that it's possible to figure out how it happened, but it absolutely does not "make sense" in terms of being a reasonable language design decision. It's 100% incompetence on the part of the person who created Javascript.

[–] Alexstarfire@lemmy.world 8 points 2 days ago (1 children)

I mean, I'd never try to do this anyway because if the types aren't the same unexpected things can happen. That's like programming 101.

[–] grue@lemmy.world 12 points 2 days ago (1 children)

Exactly, which is why designing the language to allow it is incompetence.

[–] Alexstarfire@lemmy.world 1 points 2 days ago
[–] fushuan@lemm.ee 2 points 2 days ago (1 children)

It makes perfect sense if the Lang objective is to fail as little as possible. It picks the left side object, checks if the operand is a valid operand of the type. If it is, it casts the right variable into that type and perform the operand. If it isn't, it reverses operand positions and tries again.

The issue here is more the fact that + is used both as addition and as concatenation with different data types. Well, not an issue, just some people will complain.

[–] grue@lemmy.world 2 points 1 day ago

Computing a nonsensical result is itself a failure. Continuing to run while avoiding giving an error in that case accomplishes nothing but to make the program harder to debug.

Thanks for saving me the typing.