this post was submitted on 17 May 2025
69 points (93.7% liked)

Programmer Humor

35713 readers
21 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
top 15 comments
sorted by: hot top controversial new old
[–] davel@lemmy.ml 28 points 2 days ago (1 children)

Definitionally in IEEE floating point, NaN is not equal to anything, including itself. The only real abomination here is B:

> Math.min()
Infinity
> Math.max()
-Infinity
> 
[–] Ephera@lemmy.ml 20 points 2 days ago (2 children)

I mean, B does make some amount of sense, if you realize that it's supposed to give you the maximum among the parameters (so you'd normally call it as Math.max(5, 3) === 5).

Well, and you can call that with zero parameters, because you can spread an array into it, which might have zero length. And then given these conditions, and if you don't want to throw an error, then -Infinity is kind of the least bad remaining option, as it's likely to generally work with the rest of your logic.

[–] NewDark@hexbear.net 5 points 1 day ago

I love javascript. It's so insane in such fun ways to prevent itself from throwing errors. It's got like a naive cute charm to it ya know?

[–] mathemachristian@hexbear.net 3 points 1 day ago

thats how we often do it in math. The minimum over the empty set is ∞

[–] twice_hatch@midwest.social 2 points 1 day ago

Moot! Those ALL fail code review!

[–] thoughtfuldragon@lemmy.blahaj.zone 6 points 2 days ago (2 children)
[–] CapriciousDay@lemmy.ml 1 points 1 day ago

Just because it's not a number, doesn't mean it's the same not number. But what if it is? 🙃

[–] yogthos@lemmy.ml 2 points 2 days ago
[–] tfed@infosec.exchange 3 points 1 day ago

@yogthos i afraid of (0 == '') :blob_grinning_sweat:

[–] lowleveldata@programming.dev 3 points 1 day ago

A && B && C && D

[–] salmoura@lemmy.eco.br 3 points 2 days ago (1 children)

It can't be anything other than B, right?

[–] yogthos@lemmy.ml 7 points 2 days ago
[–] ClathrateG@hexbear.net 1 points 1 day ago* (last edited 1 day ago) (1 children)

is D two single quotes, or one double quote?

[–] yogthos@lemmy.ml 3 points 1 day ago (1 children)

I'm guessing single quotes, since a single double quote isn't valid syntax.

[–] MyNameIsRichard@lemmy.ml 3 points 1 day ago

Yeah, not even JavaScript is that insane!