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

Programmer Humor

23806 readers
3167 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
[–] cupcakezealot@lemmy.blahaj.zone 2 points 3 hours ago* (last edited 3 hours ago)

javascript is to web developers what powerpoint is to sales people

[–] ZILtoid1991@lemmy.world 1 points 3 hours ago

What no type safety does to an MF...

[–] arc@lemm.ee 14 points 21 hours ago* (last edited 21 hours 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 16 hours ago

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

[–] REDACTED@infosec.pub 26 points 1 day ago (2 children)

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

[–] gmtom@lemmy.world 16 points 21 hours ago

The problem is consistency.

[–] zagaberoo@sopuli.xyz 43 points 1 day 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 1 day 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 22 points 21 hours ago (1 children)

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

[–] FooBarrington@lemmy.world 5 points 21 hours 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 5 points 18 hours 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.

[–] FooBarrington@lemmy.world 2 points 17 hours ago* (last edited 17 hours ago)

That's your prerogative, but it honestly doesn't make sense. Typescript adds almost no functionality to JS (and the few pieces it adds are now considered mistakes that shouldn't be used anymore). It only focuses on adding typing information, and in the future you'll be able to run TS that doesn't use those few added features as JS (see the proposal).

You can also add the TS types as comments in your JS code, which IMO shows that it's not a different language.

[–] spacecadet@lemm.ee 8 points 1 day ago (3 children)

So, just don’t use JavaScript?

[–] matlag@sh.itjust.works 7 points 19 hours 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 18 hours ago

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

[–] FooBarrington@lemmy.world 1 points 17 hours ago* (last edited 17 hours ago)

JS itself is great, I prefer it to most other languages due to the flexibility that it allows. Adding types through TS to safeguard against footguns doesn't mean you're not still using JS. You can also add the types using comments instead if you prefer it, which means you're actually writing raw JS.

[–] sebsch@discuss.tchncs.de 1 points 17 hours ago

Yeah! Wasm is a thing. At least rust and go are pretty neat in the browser lately.

We should leave that pile of semantics and just go further with web development

[–] FooBarrington@lemmy.world 3 points 22 hours ago

I wouldn't use raw JS for anything new, yes. Typescript however is an excellent language.

[–] calavera@lemmy.zip 3 points 18 hours ago (3 children)
[–] PieMePlenty@lemmy.world 1 points 4 hours 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.

[–] qaz@lemmy.world 27 points 17 hours ago (1 children)
[–] mapleseedfall@lemmy.world 5 points 13 hours ago (1 children)

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

[–] zzx@lemmy.world 8 points 17 hours ago

.... It does?

[–] kamen@lemmy.world 4 points 21 hours ago

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

[–] bitjunkie@lemmy.world 2 points 19 hours ago* (last edited 19 hours ago) (1 children)

It's because + is two different operators and overloads based on the type to the left, while - is only a numeric operator and coerces left and right operands to numeric. But frankly if you're still using + for math or string concatenation in 2025, you're doing it wrong.

[–] Hadriscus@lemm.ee 8 points 19 hours ago (3 children)

I know nothing about javascript, what is wrong with using + for math? perhaps naively, I'd say it looks suited for the job

[–] __Lost__@lemmy.dbzer0.com 15 points 18 hours ago (1 children)

The correct way to do it is to load a 500mb library that has an add function in it.

load more comments (1 replies)
[–] Quibblekrust@thelemmy.club 6 points 18 hours ago

It's much better to make your own function that uses bitwise operations to do addition.

function add(a, b) {
    while (b !== 0) {
        // Calculate carry
        let carry = a & b;

        // Sum without carry
        a = a ^ b;

        // Shift carry to the left
        b = carry << 1;
    }
    return a;
}

(For certain definitions of better.)

[–] bitjunkie@lemmy.world 1 points 16 hours ago* (last edited 16 hours ago)

The native arithmetic operators are prone to floating point rounding errors

[–] Kacarott@aussie.zone 19 points 1 day ago (6 children)
[–] adrian783@lemmy.world 1 points 5 hours ago

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

[–] wabasso@lemmy.ca 3 points 22 hours ago

Haha that’s a great site. But I think the C example is actually reasonable behaviour.

[–] candyman337@sh.itjust.works 8 points 1 day ago

Oh wow, that's upsetting

load more comments (3 replies)
[–] avidamoeba@lemmy.ca 205 points 1 day ago* (last edited 1 day ago) (22 children)

This is too stupid so I had to check.

Fuck me.

[–] Gsus4@mander.xyz 112 points 1 day ago* (last edited 1 day ago) (12 children)

Hm, playing devil's advocate, I think it is because the minus has not been defined as a string operation (e.g. it could pop the last char), so it defaults to the mathematical operation and converts both inputs into ints.

The first is assumed to be a concat because one of the parcels is a string...

It's just doing a lot of stuff for you that it shouldn't be in first place 🤭

load more comments (12 replies)
load more comments (21 replies)
[–] yogsototh@programming.dev 10 points 1 day ago
[–] capybara@lemm.ee 31 points 1 day 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 1 day ago (11 children)

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

[–] bss03@infosec.pub 2 points 22 hours ago

I think it's less about type system, and more about lack of a separate compilation step.

With a compilation step, you can have error messages that developers see, but users don't. (Hopefully, these errors enable the developers to reduce the errors that users see, and just generally improve the UX, but that's NOT guaranteed.)

Without a compilation step, you have to assign some semantics to whatever random source string your interpreter gets. And, while you can certainly make that an error, that would rarely be helpful for the user. JS instead made the choice to, as much as possible, avoid error semantics in favor of silent coercions, conversions, and conflations in order to make every attempt to not "error-out" on the user.

It would be a very painful decade indeed to now change the semantics for some JS source text.

Purescript is a great option. Typescript is okay. You could also introduce a JS-to-JS "compilation" step that DID reject (or at least warn the developer) for source text that "should" be given an error semantic, but I don't know an "off-the-shelf" approach for that -- other than JSLint.

load more comments (10 replies)
load more comments
view more: next ›