r/ProgrammerHumor • • Mar 20 '24

Meme areJSDevsActuallySane

Post image
14k Upvotes

554 comments sorted by

View all comments

Show parent comment

2

u/dagbrown Mar 21 '24

It's not casting anything.

What it's doing is taking the representation of an empty object, as should be used only for debugging purposes, treating that as a string, and then going on to parse that debugging representation string as a regex. It's absolutely bonkers.

It's like someone in Python going "oh, this object doesn't have a __str__ method defined, but I really need a string! Should I raise an exception? Fuck it, no, I'll just get whatever string I need out of __repr__ instead!"

1

u/[deleted] Mar 21 '24

Doesn't str default to repr when not defined though?