• Kimano@lemmy.world
    link
    fedilink
    arrow-up
    11
    ·
    2 years ago

    My personal code readability axe to grind is nested complex ternary operators.

    Every now and then I’ll see something like this

    return (checkFormatType(currentObject.type==TYPES.static||currentObject type==TYPES.dynamic?TYPES.mutable:TYPES.immutable)?create format("MUTABLE"):getFormat(currentObject));

    And I have a fucking conniption because just move that shit into a variable before the return. I get it when sometimes you just need to resolve something inline, but a huge amount of the time that ternary can be extracted to a variable before the ternary, or just rewrite the function to take multiple types and resolve it in the function.

    • dejected_warp_core@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      2 years ago

      In a one-liner competition, sure.

      In my codebase? I’d pull a “let’s linger after standup about your PR” and have the coder sweat through a 10 minute soapbox about nothing before laying down the law.

    • Skullgrid@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      no but bro, the code complexity tool says that this scope has 14 complexity instead of 13, we gotta cram it in a single ternary for code legibility