The Ambiguous Agony of Operator Overloading in Programming
Description
The image uses a popular meme format featuring a man, resembling Steve Harvey, as a contestant on a game show, looking utterly stressed and wide-eyed. The question on the screen reads, 'In Computer Programming; 1 + 1 ='. The four multiple-choice options are A: 11, B: 2, C: 10, and D: '11'. This meme hilariously captures a core complexity in programming. The joke is that without specifying the programming language or the data types of the operands, multiple answers could be correct. In mathematical addition, the answer is 2. In many languages with type coercion (like JavaScript), adding a number to a string results in string concatenation, making '11' a possibility. The binary representation of 2 is 10. For senior developers, this is a nod to the countless hours spent debugging issues stemming from weak typing and unexpected operator behavior, where the fundamental rules of math don't always apply as expected
Comments
52Comment deleted
The real answer is E: `undefined`. The question is from a legacy system, the documentation is missing, and the original developer now runs an alpaca farm
Real answer: E) Depends on whether your senior architect remembered to enable 'use strict' before the daily stand-up
After 20 years in the industry, the real shock isn't that 1+1 can equal 11, 2, 10, or "11" - it's that we've collectively decided to ship production code where this ambiguity is considered a 'feature' and not a design flaw. Steve's face perfectly captures every senior engineer's reaction when reviewing JavaScript PRs that rely on implicit type coercion instead of explicit type checking
The correct answer depends entirely on whether you're in JavaScript land where '1' + 1 === '11', Python where it throws a TypeError unless both are strings, or if you're working in binary where 1 + 1 = 10. This is why TypeScript exists - so we can argue about types at compile time instead of discovering at 3 AM in production that someone concatenated user IDs instead of summing them. The real question is: which language's type coercion rules are you debugging today?
In our polyglot stack, 1+1 is 2 in Go, "11" in Node, 10 in the Spark job, and 11 in the PM's slide deck - hence the postmortem
Pick B for Ints, C when the UI prints base‑2, D if '+' is a monoid append - and A when legacy PHP concatenates then auto‑casts; the senior answer is always E: it depends
Senior dev buzzes: 'What is "it depends on types and language"?' - the real final Jeopardy
B Comment deleted
Not always Comment deleted
depends. Comment deleted
"Yes" Comment deleted
parsing error: "1+1" is not correct l-value Comment deleted
start of text Comment deleted
All are true. A) roman numbers B) decimal numbers C) binary numbers D) string concatenation Comment deleted
Why the fuck would you evaluate it with string concatenation when strings would have "1"+"1" notation? Comment deleted
Reminds me of this one : Hi please answers the following question: What if c = 1 then c++ is: A) null B) 2 C) error D) c# E) why using c++ if you have Java F) true G) a programming language H) 42 I) 'What' was not declared in this scope Comment deleted
E Comment deleted
Why null? I mean even if we consider that "c++" is an increment of some kind of pointer, we cannot predict which data would be in the next memory cell, probably it could be some junk Comment deleted
Because operator overloading may yield any value of any return type. 🤗 Comment deleted
given there’re no quotes, it should be “B” (as there are no references to binary or strings) Comment deleted
declare A=1+1 echo $A outputs 1+1 😝 Comment deleted
binary? js ? string? integer? Comment deleted
Do you see the ;? Comment deleted
How can there be so many wrong answers? “But it can be this too and maybe its this and that” dudes look at the ; and the Syntax. It’s some kind of C/Java/Swift. With this information we already know that those numbers not in quotes cannot be string. Also they cannot represent binary either because in all of these languages you would need a 0b prefix or b suffix to make them binary numbers… and why would it be (int)11 in any of those situations… lmao Comment deleted
be cause it is not actually a line of code or statement of an specific language Comment deleted
Show me a language where any of those answers would be possible. Comment deleted
I am not talking about the language I'm talkin' about the concept Comment deleted
Then explain. Comment deleted
you may answer the question "what is VI?" as: it is a cli text/code editor but the concept may refer to a roman number, 6 in this case Comment deleted
What does this have to do with it? Comment deleted
1 + 1 = ? is a way of representing a mathematical operation to someone that assumes 1 to be only a decimal value, you are right, but one may assume that 1 is the value and depending on different representations of a value this might seem like just a psuedo code and not an actual statement to be given to a compiler or interpreter and answer the question with the returned value Comment deleted
If it would be anything other than decimal we would mark it… in most programming languages with 0x/0b prefix or b or h suffix… in actual mathematical statement we would mark it with a subscript b/h or the base like 2/16. If you don’t mark it its your fault and it is considered as decimal… Comment deleted
if we don't know the context some assumptions are not impossible but improbable Comment deleted
That’s a Mars Climate Orbiter problem. I could also assume they overwritten the + operator but nobody talks about that because it is not mentioned… Comment deleted
I don't know what that astrological thing is, but yes exactly Comment deleted
Its a spacescraft where the software writers mixed up the metric and imperial system units. So it failed its duty Comment deleted
bruh Comment deleted
Except 2 Comment deleted
In the statement it is without quotes… so you changed it… which does not really make the original question result “11” Comment deleted
btw @RiedleroD Comment deleted
thanks, it's votekick btw, not kickvote Comment deleted
Having kickvote alias for votekick sounds good btw 👀 Comment deleted
hmm, PRs are always welcome :P Comment deleted
I would be happy to do so but your PR with initial feature of votekick isn’t merged it 👀️️️️️️ Comment deleted
Are you done with aliasing or shall I take part? Comment deleted
@RiedleroD NFT ad with no relation to the post 🗑&🔨 Comment deleted
who was that? Comment deleted
linegel.t.me Comment deleted
Tf is wrong with those links Comment deleted
lmao linegel isn't trusted Comment deleted
sucks to suck 🤷 Comment deleted
is that base 5 or 6 ? Comment deleted