r/ProgrammerHumor • • Mar 20 '24

Meme areJSDevsActuallySane

Post image
14k Upvotes

554 comments sorted by

View all comments

89

u/Leonhart93 Mar 20 '24

This is the n-th post I see about accidental object to string conversions, while in like 10y of writing a ton of JS with various frameworks it happened by accident around...3 times. This underlines very clearly how humans are in general, they get obsessed and stuck on the most minor things that appear unusable or something at first glance, and then keep beating that dead horse.

30

u/MeltedChocolate24 Mar 20 '24

Just use typescript this is 2024 not the 90s

3

u/al-mongus-bin-susar Mar 20 '24

Typescript is great but it gets cumbersome because it really puts an accent on the types more than every other language out there. You have to litter every file with dozens of imports for every type you use, which makes decoupling harder. You end up almost having to write your application code twice, once in type logic and once in actual logic. Once you start doing something with any meaningful degree of complexity the type mess that naturally arises is more silly than C++ templates.

6

u/jasie3k Mar 21 '24

I fail to understand how types by themselves force to write logic twice.

→ More replies (2)

69

u/FedExterminator Mar 20 '24

I see what you’re saying, and this example is clearly made to highlight an extreme case, but wouldn’t the language be better if it didn’t do weird object conversions like this?

I see the argument a lot that while writing JS you don’t often encounter these language quirks as long as you structure your code well, but I tend to stand behind the idea that it would’ve been better for the language to not allow you to do these things in the first place.

26

u/sammy-taylor Mar 20 '24

JavaScript is a great language but it has parts of the spec that were really quirky decisions. Unfortunately, things like conversion to [object Object] are indeed specified behavior, not undefined behavior, and are therefore unlikely to ever change. So we just have to live with this stuff now. But as the previous commenter mentioned, in my 7 years of writing JS I’ve been tripped up by zany type conversions only maybe 3 or 4 times. Not a prevalent problem for most JS devs.

→ More replies (39)

6

u/kimtaengsshi9 Mar 20 '24

It's the same situation for JS and Python. JavaScript was originally intended for simple scripting for webpages, in earlier times when we couldn't imagine just how powerful 21st century websites would become, while Python was intended to be simple. Strict typing was either considered unnecessary or undesired. It was a conscious design choice, and back then the concept of good programming practices and engineering wasn't very mature yet.

Fast forward to today, and strict typing is more important than ever for good code and such. NodeJS and Python are among the world's most popular languages now, however since typing wasn't originally part off the language's design, they've to retrofit and introduce it in a roundabout way which won't break legacy code.

In other words, JS does weird stuff like this because of old design decisions. It's always legacy, legacy, legacy.

2

u/sofaRadiator Mar 21 '24

At least Microsoft got some of the best language developers in the world for TypeScript, and though it does have a few rough edges, overall they’ve done an astonishing job rationalizing the insanity we started with. 

Python’s typing is still… really not great. 

Better than Ruby’s, though. Urg. 

1

u/kimtaengsshi9 Mar 21 '24

Python typing is just Geneva ​Suggestions. It's added to help developers in the IDE, but strict typing is still considered against the Python philosophy.

It's not so bad tbh, for the most part, but ​​​​​​​​​​​boy do I wish there's better support for defining DataFrame type definitions.​​

2

u/vlakreeh Mar 20 '24

but I tend to stand behind the idea that it would’ve been better for the language to not allow you to do these things in the first place.

Oh definitely, but I think that's become the overall consensus within the JS ecosystem now that nearly everyone writes primarily TypeScript.

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.

→ More replies (1)

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. 

1

u/TheNorthComesWithMe Mar 20 '24

it would’ve been better for the language to not allow you to do these things in the first place

Javascript is interpreted, not compiled. It can't stop you from doing anything.

1

u/cs-brydev Mar 20 '24

Also consider that every time you see some weirdness in js that shouldn't really exist, there are developers behind the dozens of js implementations out there who routinely, every day, have to consciously force their js interpreters to behave like this, to comply with the open standard, no matter how stupid they think it is.

→ More replies (2)

4

u/lazercheesecake Mar 20 '24

That tile on the floor is actually lava, but only that one, I’ve only lost three guests to it, I don’t know why people keep complaining about it, just step around it, not that hard

Or we could use a contractor that doesn’t just have a lava tile on the floor, or at least puts up a fence so people don’t just fall in

7

u/Leonhart93 Mar 20 '24

Heh, that's one way of framing to make something appear more important, when I just said it's basically irrelevant to me, I barely noticed it's a case that exists.

→ More replies (1)

1

u/cs-brydev Mar 20 '24

Or of the 30 total interesting things to even post about Javascript, 28 or them are unexpected type conversions. So what do you expect exactly from a Javascript post? Sheer boredom? Would that make you happier?

1

u/Leonhart93 Mar 21 '24

There are a few more running jokes, like the endless amount of abstractization devs like to apply when it comes to JS, resulting in the 0 days since the last JS framework half-joke.