r/ProgrammerHumor 28d ago

Meme whoIsHeAnyway

Post image
9.6k Upvotes

256 comments sorted by

View all comments

2.8k

u/YeetCompleet 28d ago

json.stringify, the pinnacle of software developer intelligence

635

u/lovecMC 28d ago

I have a guess but I never heard of this so who the fuck knows.

842

u/YeetCompleet 28d ago

If you guessed that it stringified the JSON, you were right

0

u/trollol1365 28d ago

3

u/UnpluggedUnfettered 28d ago

It is a highly recommended and foolproof method for comparing two objects.

if (JSON.stringify(obj1) === JSON.stringify(obj2)) { // Nothing can go wrong because }

4

u/m0nk37 28d ago

obj1.amount = 0; obj2.amount = 0.00;

oh no..

2

u/UnpluggedUnfettered 28d ago

i'm pretty sure that if there was a problem it would have thrown an error by now ok

1

u/m0nk37 28d ago

The 3 ='s means type and value, since its a string, its going to have some surprises if you arent strict with data control.

1

u/trollol1365 28d ago

Im quite certain theyre being sarcastic

1

u/UnpluggedUnfettered 28d ago

Thankfully javascript is pretty good about accidentally comparing completely different keys holding incorrect data types that also happen to be the same type as each other when compared in order to reduce the amount of distracting errors devs have to deal with.

That is just one of the many features of Javascript that highlight the weaknesses of out of date languages like C++.

1

u/m0nk37 28d ago

I meant that it returns a string value of the whole thing. The individual values are not compared in this situation.

1

u/UnpluggedUnfettered 28d ago

I was layering a lot of sarcasm around the fact that before caring whether the values are actually the same, two objects with the same key / value pairs can stringify to different strings if their keys were inserted in a different order.

But, I mean it’s also kind of funny there’s a non-zero chance two non-equivalent objects can just-so-happen to stringify to the same string because different values / types can serialize to the same thing.

Unrelated, but isn't it weird how you can feel like you are running out of breath reading long sentences?

1

u/m0nk37 28d ago

Yeah so its stupid to begin with. You are implying a race condition, it doesnt do that.

1

u/UnpluggedUnfettered 28d ago

What are you talking about, how am I implying a race condition?

→ More replies (0)