• JakenVeina@lemm.ee
    link
    fedilink
    arrow-up
    1
    ·
    10 months ago

    Until JS supports switch expressions, nested ternaries will continue to be the most effective way to write multi-state conditionals.

    Also, stop using linting tools that prioritize consistency over human readability, and then complaining that the code they generate is not easily-readable by humans.

  • kassuro@feddit.de
    link
    fedilink
    arrow-up
    1
    ·
    10 months ago

    I often have the pleasure of refactoring this mess. And sometimes it’s not just 2 ternaries but like 4 or 5 thrown together. It took like half an hour to even understand what was going on. If you do this, you are just an evil person…

    So I totally support this. Stop this shit…

    • folkrav@lemmy.ca
      link
      fedilink
      arrow-up
      1
      ·
      10 months ago

      This shit always leaves me wondering who even writes this crap. The answer is more often than not a junior that just discovered code golf thinking he’s oh so clever. You learn to appreciate boring code, with experience…

      • kassuro@feddit.de
        link
        fedilink
        arrow-up
        1
        ·
        10 months ago

        Totally agree with you. I’m always an advocate for boring and easy to understand code.

        I really don’t need an extra layer of complexity just so someone can save a line or two.

  • BrianTheeBiscuiteer@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    7 months ago

    Seems a bit shitty they mention the article by Eric Elliott (one of the first search results if you search “nested ternaries”) but they don’t take his advice.

    This doesn’t seem ugly to me at all (left out animal so I didn’t have to type as much):

    const animalType =
      canBark() && isScary() ? 'wolf'
      : canBark() ? 'dog'
      : canMeow() ? 'cat'
      : 'rabbit';
    
  • CameronDev@programming.dev
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    10 months ago

    Does this article need to exist? I assumed anyone writing a nested ternary was intentionally writing shit code

  • hoot@lemmy.ca
    link
    fedilink
    arrow-up
    0
    ·
    10 months ago

    I’ll be sending this article to my dev teams. It’s right up there with “stop writing Helper classes”.