r/ProgrammerHumor • • Mar 20 '24

Meme areJSDevsActuallySane

Post image
14k Upvotes

554 comments sorted by

View all comments

Show parent comment

2

u/sofaRadiator Mar 21 '24

Yes, people shouldn’t make excuses for stupid behaviour like this. But at least if you look at any APIs added to the platform in the last five or ten years, they throw errors like you’d hope a sane language would. And any responsible developer these days will be using typescript and avoid 99% of these issues ahead of time. It’s a pretty good experience if you’re using modern tools, but the legacy baggage is going to be with us forever. 

1

u/theKrissam Mar 21 '24

Which part of this behavior is stupid though?

Being able to declare a new object with {}? Having methods expecting strings automatically convert objects to their string representation? having the default string representation of objects being [object Object]?

1

u/Eva-Rosalene Mar 21 '24

Having methods expecting strings automatically convert objects to their string representation?

Mostly this one.

1

u/theKrissam Mar 21 '24

Doesn't most languages do this though?

1

u/Eva-Rosalene Mar 21 '24

Huh? I can't say about "most", but most that I am aware of or used, no.

Also, even if that was true. That's still very error-prone thing, even if everyone else does it. While I don't agree that JS is really bad language overall, this shit is bad.

1

u/theKrissam Mar 21 '24

I mean, I've only done Ruby and C# in my professional life, but they both do it and I know from school that Java does it and I think python does too? I don't know, those could be outliers and be the only ones who does this.

But I don't see how it's errorprone though.

2

u/sofaRadiator Mar 21 '24

I don’t think any of the languages you’ve named do this to the same extent as JavaScript. I could be wrong, but if I recall correctly Java and C# will coerce to a string if you’re concatenating, but will still throw an error if you’re passing to a function that expects a string (like this case in JavaScript). I don’t think Python implicitly coerces anywhere (outside of functions like print and explicit string interpolation). I’m not sure about Ruby, but I think it only coerces certain string-like types in certain contexts.

Old JavaScript would coerce everywhere imaginable because it really didn’t want to throw errors. 

The languages that maybe do similar with I can think of are Perl and Php. 

1

u/sofaRadiator Mar 21 '24

No. Some old bad ones do. Modern ones only do in specific contexts where string interpolation is explicitly indicated or the result is immediately meant for displaying to a user. Automatically converting when you call print makes sense since the functions role is converting from structured data to human output. Creating a regex matcher is not a case where that makes sense.