Skip to content
DevMeme
5118 of 7590
Languages Post #5602 · source on Telegram

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

52
Anonymous ★ Top Pick 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
  1. Anonymous ★ Top Pick

    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

  2. Anonymous

    Real answer: E) Depends on whether your senior architect remembered to enable 'use strict' before the daily stand-up

  3. Anonymous

    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

  4. Anonymous

    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?

  5. Anonymous

    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

  6. Anonymous

    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

  7. Anonymous

    Senior dev buzzes: 'What is "it depends on types and language"?' - the real final Jeopardy

  8. @trainzman 2y

    B

    1. @LilTemmieh 2y

      Not always

  9. Deleted Account 2y

    depends.

  10. @Nefrace 2y

    "Yes"

  11. @AlexAparnev 2y

    parsing error: "1+1" is not correct l-value

  12. @azizhakberdiev 2y

    start of text

  13. @randomrabe 2y

    All are true. A) roman numbers B) decimal numbers C) binary numbers D) string concatenation

    1. @sevos 2y

      Why the fuck would you evaluate it with string concatenation when strings would have "1"+"1" notation?

  14. @randomrabe 2y

    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

    1. @RoberaRobera 2y

      E

    2. @mon_faleymon 2y

      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

      1. @SamsonovAnton 2y

        Because operator overloading may yield any value of any return type. 🤗

  15. @DavidGarciaCat 2y

    given there’re no quotes, it should be “B” (as there are no references to binary or strings)

    1. @SamsonovAnton 2y

      declare A=1+1 echo $A outputs 1+1 😝

  16. @callofvoid0 2y

    binary? js ? string? integer?

  17. @dsmagikswsa 2y

    Do you see the ;?

  18. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

    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

    1. @callofvoid0 2y

      be cause it is not actually a line of code or statement of an specific language

      1. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

        Show me a language where any of those answers would be possible.

        1. @callofvoid0 2y

          I am not talking about the language I'm talkin' about the concept

          1. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

            Then explain.

            1. @callofvoid0 2y

              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

              1. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

                What does this have to do with it?

                1. @callofvoid0 2y

                  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

                  1. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

                    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…

                    1. @callofvoid0 2y

                      if we don't know the context some assumptions are not impossible but improbable

                      1. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

                        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…

                        1. @callofvoid0 2y

                          I don't know what that astrological thing is, but yes exactly

                          1. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

                            Its a spacescraft where the software writers mixed up the metric and imperial system units. So it failed its duty

                            1. @callofvoid0 2y

                              bruh

  19. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

    Except 2

  20. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

    In the statement it is without quotes… so you changed it… which does not really make the original question result “11”

  21. @callofvoid0 2y

    btw @RiedleroD

    1. @RiedleroD 2y

      thanks, it's votekick btw, not kickvote

      1. dev_meme 2y

        Having kickvote alias for votekick sounds good btw 👀

        1. @RiedleroD 2y

          hmm, PRs are always welcome :P

          1. dev_meme 2y

            I would be happy to do so but your PR with initial feature of votekick isn’t merged it 👀️️️️️️

            1. @callofvoid0 2y

              Are you done with aliasing or shall I take part?

  22. @CcxCZ 2y

    @RiedleroD NFT ad with no relation to the post 🗑&🔨

  23. @purplesyringa 2y

    who was that?

    1. @sylfn 2y

      linegel.t.me

      1. dev_meme 2y

        Tf is wrong with those links

      2. @RiedleroD 2y

        lmao linegel isn't trusted

  24. @RiedleroD 2y

    sucks to suck 🤷

  25. @callofvoid0 2y

    is that base 5 or 6 ?

Use J and K for navigation