this post was submitted on 04 Jun 2025
1035 points (98.6% liked)

Programmer Humor

24079 readers
1009 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
 
top 50 comments
sorted by: hot top controversial new old
[–] REDACTED@infosec.pub 27 points 6 days ago (2 children)

Imagine doing math with strings and then blaming the language not yourself

[–] zagaberoo@sopuli.xyz 43 points 6 days ago (1 children)

The risk is when it happens unintentionally. The language is bad for hiding such errors by being overly 'helpful' in assuming intent.

[–] FooBarrington@lemmy.world 6 points 6 days ago (2 children)

Sure, but at this point it's your own fault if you don't use Typescript to keep these issues from happening.

[–] jjjalljs@ttrpg.network 23 points 6 days ago (1 children)

"Use a different language" is a common defense of javascript, but kind of a weird one.

[–] FooBarrington@lemmy.world 5 points 6 days ago (1 children)

Not really, considering Typescript only adds static types to JS. It's not a different language, it's an extension.

[–] Quibblekrust@thelemmy.club 7 points 6 days ago (1 children)

Since it needs to be compiled to JavaScript in order to be used, I kind of consider it a different language. Yes, it's a strict superset of JavaScript, but that makes it different.

load more comments (1 replies)
[–] spacecadet@lemm.ee 9 points 6 days ago (3 children)

So, just don’t use JavaScript?

[–] matlag@sh.itjust.works 8 points 6 days ago (2 children)

That's also my understanding: "Javascript is great because you can use other languages and then transpile them to JS."

[–] KeenFlame@feddit.nu 3 points 6 days ago

Oh man machine language is so good, literally the best actually

load more comments (1 replies)
load more comments (2 replies)
[–] gmtom@lemmy.world 16 points 6 days ago

The problem is consistency.

[–] capybara@lemm.ee 31 points 6 days ago (1 children)

To start off... Using arithmetic operators on strings in combination with integers is a pure skill issue. Let's disregard this.

If you were to use + where one part is a string, it's natural to assume a string appending is desired since + is commonly used as a function for this. On the other hand, - is never used for any string operation. Therefore, it's safe to assume that it relates to actual artihmetics and any strings should therefore be converted to numerical values.

This is an issue with untyped languages. If you don't like it, use typescript. End of story.

[–] Jankatarch@lemmy.world 32 points 6 days ago (2 children)

Instead of trying to make it work, javascript could just say "error." Being untyped doesn't mean you can't have error messages.

[–] capybara@lemm.ee 6 points 6 days ago (4 children)

This is fair enough from an idealistic view. In practice, you don't want your entire website to shit itself because of a potentially insignificant error.

[–] Kacarott@aussie.zone 22 points 6 days ago (2 children)

This is exactly why it should throw an error, to make it incredibly obvious something isn't working correctly so it can be fixed. Otherwise you have wrong logic leading to hard to notice and hard to debug problems in your code

load more comments (2 replies)
[–] Jankatarch@lemmy.world 10 points 6 days ago (1 children)

In practice runtime errors are a bitch to find and fix.

load more comments (1 replies)
[–] random8847@lemmy.world 8 points 6 days ago (1 children)

I'd rather have my website shit itself than have silent difficult to find errors.

load more comments (1 replies)
[–] Valmond@lemmy.world 5 points 6 days ago (1 children)

Look! I bought this for free on capybaras website, there's a glitch!

capybara: at least it didn't throw an error.

/ jk 😁

load more comments (1 replies)
load more comments (1 replies)
[–] arc@lemm.ee 14 points 6 days ago* (last edited 6 days ago) (1 children)

Javascript is a dogshit language that everyone is stuck with. The best that we can hope for is the likes of typescript take the edge off of it. Even though it's like smearing marzipan over a turd. At least it's ok if you don't take a deep bite.

[–] Fijxu@programming.dev 6 points 6 days ago

JS should have never leaved the Browser side. Now you can use this thing for Backend and is just awful

[–] Kacarott@aussie.zone 20 points 6 days ago (6 children)
[–] candyman337@sh.itjust.works 8 points 6 days ago

Oh wow, that's upsetting

F#? What? We can't curse on the internet? Self censorship at dictator levels here. /s

[–] adrian783@lemmy.world 2 points 5 days ago

so plus coerces into string if not number, was that so hard?

load more comments (2 replies)
[–] yogsototh@programming.dev 10 points 6 days ago
[–] proctor1432@lemmy.world 12 points 6 days ago

Heck, I need to learn some new languages apparently. Here I was expecting an angry "CS0029 cannot implicitly convert type 'string' to 'int'!

[–] bss03@infosec.pub 11 points 6 days ago* (last edited 6 days ago) (1 children)

This is my favorite language: GHC Haskell

GHC Haskell:

GHCi> length (2, "foo")
1
[–] yetAnotherUser@lemmy.ca 6 points 6 days ago (5 children)

Wait, now I need to know why.

* some time later *

I went to check why the hell this happened. It looks like the pair ("(,)") is defined as an instance of Foldable, for some reason, which is the class used by functions like foldl() and foldr(). Meanwhile, triples and other tuples of higher order (such as triples, quadruples, ...) are not instances of Foldable.

The weirdest part is that, if you try to use a pair as a Foldable, you only get the second value, for some reason... Here is an example.

ghci> foldl (\acc x -> x:acc) [] (1,2)

[2]

This makes it so that the returned length is 1.

[–] bss03@infosec.pub 6 points 6 days ago

Oddly enough, in Haskell (as defined by the report), length is monomorphic, so it just doesn't work on tuples (type error).

Due to the way kinds (types of types) work in Haskell, Foldable instances can only operate over (i.e. length only counts) elements of the last/final type argument. So, for (,) it only counts the second part, which is always there exactly once. If you provided a Foldable for (,,,) it would also have length of 1.

load more comments (4 replies)
[–] calavera@lemmy.zip 5 points 6 days ago (3 children)
[–] qaz@lemmy.world 29 points 6 days ago (1 children)
[–] mapleseedfall@lemmy.world 6 points 5 days ago (1 children)

This here is my absolute favorits way to diss someone. Send the a wikipeda link and bam!

load more comments (1 replies)
[–] zzx@lemmy.world 8 points 6 days ago

.... It does?

[–] PieMePlenty@lemmy.world 2 points 5 days ago

It does to some degree.

  • "11" is string, 1 is an int, because strings can be added (+) convert int to string and combine: "11"+"1" = "111"
  • "11" is string, 1 is an int, because strings cant be subtracted (-) convert string to int and combine: 11-1 = 10

I'm not into JS so I don't know how it takes priority. ints can be added too, so I guess its basing it on the first variable which is compatible with the operator: in the first case string, in the second case int.

If this is how it works, it makes sense. But imo its a case of the designers being preoccupied with whether or not they could, they didn't stop to think if they should.

[–] kamen@lemmy.world 4 points 6 days ago

If you're consciously and intentionally using JavaScript like that, I don't want to be friends with you.

[–] cupcakezealot@lemmy.blahaj.zone 2 points 5 days ago* (last edited 5 days ago)

javascript is to web developers what powerpoint is to sales people

load more comments
view more: next ›