Skip to content
DevMeme
5773 of 7590
Languages Post #6329 · source on Telegram

C++ Operator Overloading Elegance vs. Java's Philosophical Stand

Description

This meme uses the 'Soyjack vs. Chad' format to compare the language philosophies of Java and C++. On the left, a crying Wojak character (Soyjack) with the Java logo on his forehead complains, 'OPERATOR OVERLOADING ONLY MAKES IT HARDER TO UNDERSTAND AND IT'S AGAINST OUR PHILOSOPHY', followed by a wall of unreadable text. This panel represents a rigid, dogmatic viewpoint. On the right, a stoic, bearded 'Chad' character with the C++ logo on his head states calmly, 'IF YOU DIVIDE A PATH WITH ANOTHER PATH IT, MEANS IT IS A SUBFOLDER'. Below this is a clear C++ code snippet demonstrating this concept: `path f1("folder1"); path f2("folder2"); path dir = f1 / f2;`, with a comment showing the result `// folder1\\folder2`. The humor arises from the stark contrast between Java's verbose, philosophical rejection of a feature and C++'s pragmatic and intuitive application of that same feature (operator overloading) to make code more readable and elegant, specifically for filesystem path manipulation

Comments

22
Anonymous ★ Top Pick Java's philosophy is to protect developers from complexity by removing features, while C++'s philosophy is to trust developers to manage complexity, even if it means occasionally dividing a string by a string to build a path
  1. Anonymous ★ Top Pick

    Java's philosophy is to protect developers from complexity by removing features, while C++'s philosophy is to trust developers to manage complexity, even if it means occasionally dividing a string by a string to build a path

  2. Anonymous

    Java will spin up three interfaces and a PathBuilderFactory to keep ‘/’ pure; C++ just writes dir = f1 / f2 - then Windows swaps the slashes and philosophy dies in CI

  3. Anonymous

    After 20 years in the industry, I've realized the real operator overloading was the technical debt we accumulated trying to explain to junior devs why path.resolve(path.join(basePath, subPath)) is somehow more 'readable' than path1 / path2

  4. Anonymous

    The real irony? Java developers will write 'Paths.get(parent).resolve(child)' and call it 'readable,' while C++ devs just type 'parent / child' and get back to solving actual problems. Both camps are technically correct, but only one needs a paragraph to justify why their coffee cup is half empty

  5. Anonymous

    Java's anti-overloading crusade saved us from chaos; C++ just used it to make paths finally '/' intuitive

  6. Anonymous

    Java: Paths.get(a, b); C++17: a / b; Enterprise: PathJoinerFactoryFactory - the only undefined behavior is the bikeshed

  7. Anonymous

    Java: “operator overloading hurts readability.” C++: dir = f1 / f2; elegant - until f2 is absolute and the left operand vanishes, which the standard calls “well-defined” and your pager calls “incident.”

  8. @koloslolya 1y

    i mean, i can understand "folder1"/"folder1" but ahhh

  9. @zaspirin 1y

    Kotlin did it too for Path lol

    1. @Box_of_the_Fox 1y

      So java will do it too in some future version xd

      1. @FirokOtaku 1y

        JCP: no, we won't

  10. @LeakyRectifiedLinearUnit 1y

    > no operator overloading > looks inside > '+' for string concatenation

  11. @ZgGPuo8dZef58K6hxxGVj3Z2 1y

    Hell naw Java is cooking something

  12. @anysound 1y

    *trying to write “hello world” in C++* “They bitwise shift what by what??”

    1. @ZgGPuo8dZef58K6hxxGVj3Z2 1y

      The stream by a literal /s

    2. @callofvoid0 1y

      *they push buncha characters to a file stream* *which file? what is a stream?*

  13. @xyz941d 1y

    Same in python I guess, I've seen some weird shit like BASE_DIR / 'logs'

    1. @firs_iln 1y

      if using pathlib and Path object you could do so

  14. @misesOnWheels 1y

    you can just implement the same functionality using methods with less confusion

    1. @karim_mahyari 1y

      The argument is how things look, not what they mean.

  15. @chipmunkcustodian 1y

    That's barbaric, who does that?

  16. @chipmunkcustodian 1y

    Long live path.resolve

Use J and K for navigation