this post was submitted on 24 Nov 2025
555 points (89.4% liked)

Programmer Humor

27490 readers
1557 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] arcterus@piefed.blahaj.zone 20 points 1 day ago (1 children)

The completely bizarre implicit type conversions, for one thing.

[–] hperrin@lemmy.ca 7 points 1 day ago* (last edited 1 day ago) (2 children)

I’ve never really found the type conversions that bizarre, unless you’re doing something weird like casting an array to a string or number. I don’t really use strange type casts, since I use TypeScript and avoid using the “==“ operator. What other things make it not good?

[–] arcterus@piefed.blahaj.zone 17 points 1 day ago (1 children)

I mean, just the fact that you're using TS instead of plain JS (and that TS even exists) should tell you that the language has issues...

[–] hperrin@lemmy.ca 4 points 1 day ago (3 children)

It’s just strict typing on top of plain JS. I like strict typing. Some people like loose typing.

[–] arcterus@piefed.blahaj.zone 11 points 1 day ago (1 children)

I'm pretty sure most people do not like JS's loosey-goosey, who-knows-what-ur-gonna-get type system, which is why TS is so popular. Not really surprising since the bones of the language were basically spat out in a couple weeks. TS is a custom type system on top of JS, meaning it's not just JS's type system expressed through strict typing. They added a bunch of useful features like discriminated unions and so on to make using TS more pleasant than raw JS.

TS is actually usable (although NPM and the environment built around it still suck). It's inherited a bunch of weird shit from JS, but the type system generally makes them bearable.

[–] hperrin@lemmy.ca 3 points 1 day ago (1 children)

Have you ever looked at the original JS implementation? It looks nothing like what JS is today. Saying the bones were spat out in a couple weeks is like saying Linux was developed in a few months.

TS transpiles to JS, and any JS is valid TS. Take any TS, remove the types (and some syntactic sugar) and you have JS. I feel like if you like TS but not JS, you just don’t like loosely typed languages. That’s just a preference. It doesn’t make a language bad.

[–] arcterus@piefed.blahaj.zone 5 points 1 day ago* (last edited 1 day ago) (1 children)

Have you ever looked at the original JS implementation? It looks nothing like what JS is today. Saying the bones were spat out in a couple weeks is like saying Linux was developed in a few months.

And yet working groups have spent literal decades trying to make JS less shitty. The fundamental basics of JS can't be changed in backwards incompatible ways without breaking a huge number of websites. The Linux comparison is just wrong because Linux has broken backwards compatibility to fix problems. A better comparison would be Linux's policy to never break userspace. Backwards incompatible changes to JS would break a bajillion websites, much like breaking userspace would break a bajillion programs.

TS transpiles to JS, and any JS is valid TS. Take any TS, remove the types (and some syntactic sugar) and you have JS. I feel like if you like TS but not JS, you just don’t like loosely typed languages. That’s just a preference. It doesn’t make a language bad.

JS is valid TS. TS is not valid JS. This is the fundamental point. TS essentially fixes issues that JS cannot fix without breaking the world.

Loose typing is fine if the language's type system isn't insane. I prefer static typing, but as long as the type system is coherent, it's not an issue.

TBH IMO the only reason JS became popular is because it was provided by web browsers, and if you wanted to make your site do anything complex, you thus needed to use JS. This eventually led to the JS VMs being very fast, so Node was created, and now it's all over since you can learn one language for web and server.

[–] hperrin@lemmy.ca 1 points 1 day ago

JS has been made less shitty. I’ll give you that old JS was pretty shitty. Like v5 and lower were a huge pain. But a lot of that was because of the lack of modern language features that other languages had at the time. ES6 introduces some huge improvements that made JavaScript much less frustrating. Personally, at this point, I have very few pain points with the language.

I don’t think being included in browsers is the only reason JS became so popular, but it’s definitely the biggest reason. That doesn’t make it a bad language.

Backwards incompatible changes have been introduced in JS a number of times. They are opt in at the script level and enforced in newer language contexts.

I started my career with Visual Basic (3!) and I appreciated the loose typing because it meant I could get going and actually have something running quickly as a newbie. A few years later I switched to C# and saw how an entire class of errors disappeared because of the strong typing. Both have their place, depending on the skill level of the coder and the needs of the application.

[–] SaharaMaleikuhm@feddit.org 2 points 1 day ago

Yes, but some are VERY opinionated about it. It's almost religious with them. I think it's silly. Both have their pros and cons. I honestly enjoy both and never had a big issue with loosely typed languages. I assume it's just bad developers that mess up and get confused about it.

[–] FishFace@piefed.social 9 points 1 day ago (2 children)

If you use typescript you will obviously never see the weird type system of JavaScript

[–] Baguette@lemmy.blahaj.zone 5 points 1 day ago

still possible, typescript is only strongly typed if you and everyone else working on the project wants it to be.

[–] hperrin@lemmy.ca 2 points 1 day ago (1 children)

Considering TypeScript is a superset of JavaScript, you certainly can. But, that generally means you’re using TypeScript poorly.

[–] FishFace@piefed.social 0 points 1 day ago (1 children)

Just look up the video entitled "wat" which is mainly about JavaScript

[–] hperrin@lemmy.ca 2 points 1 day ago (2 children)

Yeah, I’ve seen a lot of those videos where they do things like {} + [], but why would anyone care what JS does in that case? Unless you’re a shit-ass programmer, you’re never going to be running code like that.

The idea behind that kind of type conversion was that JS was originally designed to be extremely lenient. If it ever crashed, the web page would freeze, so it lets you do things other languages just crash from, like divide by zero.

[–] FishFace@piefed.social 5 points 1 day ago (1 children)

A language's deficiencies are rarely obvious when everyone is writing it perfectly.

But a coherent type system gives the programmer confidence - for free. Do you know what [1] + [2] is in JavaScript? Do you know what type it is? JavaScript teaches you that it has operator overloading for built-in types but then it behaves in such a dumb way you can't use it.

That's explained by a desire to be extremely lenient, but it's not justified by it. Programming langauges are generally not made by idiots, so every bad decision has an explanation.

[–] hperrin@lemmy.ca 2 points 1 day ago (1 children)

I would assume [1] + [2] would give you either 0 or 2, but maybe "12". But why you ever write that? I’ve never bothered to memorize what happens there because I would never write that. The plus operator is not for arrays. It’s for numbers and strings. If you’re trying to concatenate arrays, there’s a function for that. Would you do that in Java or C? People trying to make JavaScript do silly things just because it refuses to crash when you do then calling the language bad for it is just silly to me.

[–] FishFace@piefed.social 2 points 1 day ago (1 children)

Operator overloading is a perfectly reasonable feature in a language to make use of and to assume works. If it is not going to behave sensibly, it should be an error, not nonsense, because having it work for strings but not other sequence types is surprising, and surprising is bad.

As I said, the fact that you didn't know the result means that JavaScript's type system is opaque and hard to understand. You might have understood that there are some things you "shouldn't do" but being hard to understand is a bad aspect of a language even if it doesn't prevent you from writing correct, good code.

By way of analogy, thing of a language which, like JavaScript, doesn't require semicolons, but they are accepted. Except, if you use a semicolon after the last statement in a block, that statement never gets executed. Your reply is like saying, "just don't use semicolons - they're not needed" instead of acknowledging that an element of the language which is prone to causing mistakes is bad design.

[–] hperrin@lemmy.ca 1 points 1 day ago (1 children)

I mean how can you define a sensible way to subtract Infinity from an array, or add an object to a string? The way JavaScript defines it is predictable, easy to compute, and handles bad code gracefully, which is a good tradeoff between doing something like matrix arithmetic on a CPU and just straight up crashing. If you’re doing silly things like that, you should know how JavaScript coerces types, but I don’t do silly things like that, so I don’t really care how JavaScript would handle it. Every language will do silly things if you force it to. That doesn’t make it a bad language.

Do you feel the same about C because C lets you take pointers of pointers of pointers until you’re addressing random memory in an unpredictable way? No, because it’s silly to do that.

[–] FishFace@piefed.social 2 points 1 day ago (1 children)

I mean how can you define a sensible way to subtract Infinity from an array, or add an object to a string?

TypeError.

There are also various sensible ways, for example if you have an array of floats, subtracting Infinity from the array could result in an array of the same length as the original, with each value being negative Infinity. But in general inhomogeneous types should not be addable without careful thought to create a type system which is consistent and coherent. That is exactly what JavaScript did not do.

It doesn't "handle bad code gracefully"; it handles it in a way that's hard to reason about and hence hard to work with.

The way JavaScript defines it is predictable

You literally just failed to predict it, so I don't think there's any point continuing this conversation.

[–] hperrin@lemmy.ca 1 points 1 day ago* (last edited 1 day ago) (1 children)

Ok, except I did predict it. It turns them both into strings and gives you “12”. I checked it. But I didn’t mean predictable as in, you inherently know what it’s going to do, I meant predictable as in, it will follow the same basic rules in each circumstance.

So, should web pages be prone to crashing if everything isn’t perfect? I don’t know if you remember XHTML, but that was basically what happened with that. You have a “div” within a “p”? Page crashed. You have an unclosed “span”? Page crashed. XHTML was abandoned because is constantly broke the web.

Web technologies are supposed to be resilient, so throwing TypeError is the last resort for something that absolutely cannot work, like trying to add to a Symbol. Since nothing from the user is ever a Symbol (there’s no input that can give it, and it can’t be stored in JSON), it’s acceptable to throw a TypeError there.

JavaScript is meant to be fast and resilient. Its type conversions make sense when you consider those goals.

[–] FishFace@piefed.social 1 points 22 hours ago (1 children)

Getting it on the third guess is not the brag you seem to think, and I'm still not engaging with you on the rest.

[–] hperrin@lemmy.ca 0 points 14 hours ago

I’m sorry I didn’t think it was [1,2].

[–] namingthingsiseasy@programming.dev 3 points 1 day ago (1 children)

Yeah, I’ve seen a lot of those videos where they do things like {} + [], but why would anyone care what JS does in that case? Unless you’re a shit-ass programmer, you’re never going to be running code like that.

By this same logic, memory safety issues in C/C++ aren't a problem either, right? Just don't corrupt memory or dereference null pointers. Only "a shit-ass programmer" would write code that does something like that.

Real code has complexity. Variables are written to and read from all sorts of places and if you have to audit several functions deep to make sure that every variable won't be set to some special value like that, then that's a liability of the language that you will always have to work around carefully.

[–] hperrin@lemmy.ca 2 points 1 day ago

No.

By that same logic, memory safety issues in C/C++ don’t make them bad programming languages.

If you’re worried about it, like you’re accepting input from the user, sanitize it.

if (typeof userProvidedData !== "string") {
  throw new Error("Only works on strings.");
}

Better yet, put that in a function called assertString.