• PeriodicallyPedantic@lemmy.ca
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    Bah

    Ternary is just a compressed if-elseif-else chain with a guaranteed assignment.
    If you format it like a sane person, or like you would an if/else chain, then it’s way easier to read than if/else chains.

      • PeriodicallyPedantic@lemmy.ca
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        Hey, when you gotta pick a value from a bunch of options, it’s either if/elseif/else, ternary, switch/case, or a map/dict.

        Ternary generally has the easiest to read format of the options, unless you put it all on one line like a crazy person.

        • guber@lemmy.blahaj.zoneOP
          link
          fedilink
          arrow-up
          0
          ·
          1 year ago

          me personally, i prefer switch case statements for many-value selection, but if ternary works for you, go ham (as long as you don’t happen to be the guy who’s code I keep having to scrub lol)

          • thebestaquaman@lemmy.world
            link
            fedilink
            arrow-up
            0
            ·
            1 year ago

            If there’s more than two branches in the decision tree I’ll default to a if/else or switch/case except if I want to initialise a const to a conditional value, which is one of the places I praise the lord for ternaries.