Skip to content
DevMeme
4470 of 7590
Languages Post #4902 · source on Telegram

Ternary Operator Fan Club

Description

The image is a SpongeBob crowd-reaction meme with SpongeBob yelling excitedly while other characters look startled or uncomfortable. The top text reads `I FUCKING LOVE THE TERNARY OPERATOR`, and the bottom text reads `I LOVE MAKING IF STATEMENTS IN ONE LINE`, with an `imgflip.com` watermark in the lower-left corner. The developer joke is about the ternary operator turning simple conditional logic into compact one-liners that some programmers love and others find unreadable. It reflects a real code review tension: brevity can be expressive, but nested or overused ternaries quickly become syntax golf disguised as clarity.

Comments

22
Anonymous ★ Top Pick A ternary is elegant until the third `?` turns your business rule into a CAPTCHA for maintainers.
  1. Anonymous ★ Top Pick

    A ternary is elegant until the third `?` turns your business rule into a CAPTCHA for maintainers.

  2. @RiedleroD 3y

    let x = ((y * 2)**(1/2))<4 ? 2+y/2 : 2-y/2 no comment needed, code is self-explanatory

    1. @Box_of_the_Fox 3y

      I like how in kotlin everything returns value, so you can do this with if-else

    2. @SamsonovAnton 3y

      let x = ((y * 2) ** (1/2)) < 4 ? 2 + y / 2 : 2 - y / 2 would be more readable and still better than explicit if-else, IMHO, especially when clauses grow in size and complexity.

      1. @RiedleroD 3y

        true

    3. @Vedqiibyol 3y

      2 + y / sqrt(y * 2) < 4 ? 2 : -2;

    4. @Vit_log 3y

      let x = if (y * 2).sqrt() < 4 { 2 + y/2 } else { 2 - y/2 } Looks not so bad, really (Rust lang)

      1. Deleted Account 3y

        +1

    5. @callofvoid0 3y

      what is y ?

  3. @q_rsqrt 3y

    LITERALLY ME

  4. @q_rsqrt 3y

    IF THE CODE IS COMPACT, IT IS GOOD

  5. @deerspangle 3y

    Python's one is kinda sad though :( It used to feel cool, but now it's just so bloated

  6. @deerspangle 3y

    Same with list comprehensions.. Map/filter/reduce really puts python list comprehensions to shame

  7. @Vedqiibyol 3y

    Yeaaaah! Makes even less sense now!

  8. @Box_of_the_Fox 3y

    I need to finally learn Rust, it sounds really interesting

  9. @CcxCZ 3y

    This is nothing, try functional point-free style.

  10. @Saeid025 3y

    Sadly there is no such thing in rust... We can just use one liner if and else... The worse thing is we still need to use brackets 😐 if bool { one } else { two }

    1. @bbnodollarsign 3y

      Sadly there's rust

  11. @Saeid025 3y

    Although I think we going to get it without the brackets in later versions... (Already in nightly)

  12. @im_ali_pj 3y

    golang var x int if ((y*2)**(1/2))<4 { x = 2+y/2 } else { x = 2-y/2 } 😑😂😂😂

  13. @DenDrobiazko 3y

    I hate Kotlin for not supporting this from Java 😢

  14. @dugeru42 3y

    return option1 or option2

Use J and K for navigation