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

Programmer Humor

24079 readers
1052 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
[–] 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 6 days 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 6 days ago

.... It does?

[–] PieMePlenty@lemmy.world 2 points 6 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.

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

javascript is to web developers what powerpoint is to sales people

[–] bitjunkie@lemmy.world 2 points 1 week ago* (last edited 1 week 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 1 week 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 6 days ago (1 children)

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

[–] bitjunkie@lemmy.world 0 points 6 days ago* (last edited 6 days ago)

Point taken but the one I use is only ~200k for the whole package, ~11k for the actual file that gets loaded

[–] Quibblekrust@thelemmy.club 6 points 6 days 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 6 days ago* (last edited 6 days ago)

The native arithmetic operators are prone to floating point rounding errors

[–] ZILtoid1991@lemmy.world 0 points 6 days ago

What no type safety does to an MF...

[–] avidamoeba@lemmy.ca 207 points 1 week ago* (last edited 1 week ago) (6 children)

This is too stupid so I had to check.

Fuck me.

[–] Gsus4@mander.xyz 114 points 1 week ago* (last edited 1 week ago) (4 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 🤭

[–] avidamoeba@lemmy.ca 41 points 1 week ago (1 children)

Yup. It's completely inconsistent in its interpretation of the + operator.

[–] Gsus4@mander.xyz 20 points 1 week ago* (last edited 1 week ago) (7 children)

Yeah, I actually had to try 1+"11" to check that it didn't give me 12, but thankfully ~~it commutes~~ it's consistent 😇

load more comments (7 replies)
load more comments (3 replies)
[–] jol@discuss.tchncs.de 38 points 1 week ago

From all the Javascript quiks this is the least stupid and the most obvious.

[–] irelephant@programming.dev 31 points 1 week ago (2 children)
[–] wasabi@feddit.org 36 points 1 week ago (3 children)
load more comments (1 replies)
[–] Alexstarfire@lemmy.world 20 points 1 week ago (5 children)

Unfortunately, it makes sense if you know what + means, which is concatenate. - is strictly a math function though.

Not saying that makes this better. It just makes sense.

[–] grue@lemmy.world 27 points 1 week ago* (last edited 1 week ago) (6 children)

It is 'comprehensible' in the sense that it's possible to figure out how it happened, but it absolutely does not "make sense" in terms of being a reasonable language design decision. It's 100% incompetence on the part of the person who created Javascript.

load more comments (6 replies)
load more comments (4 replies)
load more comments (2 replies)
[–] RobotZap10000 64 points 1 week ago (1 children)

[object Object][object Object]

load more comments (1 replies)
[–] whaleross@lemmy.world 43 points 1 week ago (8 children)

People that try to do mathematical operations with strings blaming the programming language that had a stated design goal to do its best and try to keep running scripts that make no sense because they realized it would be used by people that have no idea what they are doing. Clearly they were right.

[–] grue@lemmy.world 37 points 1 week ago (1 children)

the programming language that had a stated design goal to do its best and try to keep running scripts that make no sense...

...itself makes no sense. It is wrong and bad that Javascript was ever designed that way in the first place.

[–] whaleross@lemmy.world 22 points 1 week ago (2 children)

It was never intended to run full applications but only the small business scripts and hobbyist homepage stuff that were the thing in the 90s, across inconsistent browsers that were a jungle of hit and miss behaviour where it was preferred that menus keep working even if the mouse effect was not. Anything of scale was expected to be done in Java. Dynamic web pages did not exist and as anything not static was generated server side into a static html file to be rendered on the client.

Anyway, back then it wasn't considered the job of the programming language to hold the hand of the aspiring developer as it is common today. It's not a bad thing that IDE and even compilers and preprocessors try to help you write better code today, but then it simply didn't exist.

JavaScript is from a different time and because it has the hard requirement or backwards compatibility there is no changing it and has not been for thirty years except to add stuff to it.

I think it's just silly to ask the past to keep up with the present. Bad code is not the fault of the language regardless, even though junior devs and even seasoned ones like to think so to protect their ego. I think it is better to accept it, learn from it and roll with it because every single platform and language has their weird quirks anyway.

Signed, old dude that learned programming in 8 bit BASIC and 6502 machine code without an assembler, where code bad enough would freeze your machine that required a cold boot and starting over from your last save that you didn't do.

load more comments (2 replies)
load more comments (7 replies)
[–] capybara@lemm.ee 31 points 1 week 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 week 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.

load more comments (11 replies)
[–] REDACTED@infosec.pub 28 points 1 week ago (2 children)

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

[–] zagaberoo@sopuli.xyz 44 points 1 week ago (11 children)

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

load more comments (11 replies)
load more comments (1 replies)
[–] kubica@fedia.io 24 points 1 week ago (7 children)

Lets fix it. I think that since we are removing the ones, then "11" - 1 should be equal to "".

load more comments (7 replies)
[–] MinusPi@pawb.social 23 points 1 week ago (4 children)

If you mix types like that, it's your own fault

[–] raspberriesareyummy@lemmy.world 35 points 1 week ago (20 children)

BS. A language shouldn't have operators that allow non sensical operations like string concatenation when one operand is not a string.

load more comments (20 replies)
load more comments (3 replies)
[–] Kacarott@aussie.zone 20 points 1 week ago (6 children)
[–] adrian783@lemmy.world 2 points 6 days ago

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

load more comments (5 replies)
[–] python@lemmy.world 20 points 1 week ago (1 children)
load more comments (1 replies)
load more comments
view more: next ›