• DudeDudenson@lemmings.world
    link
    fedilink
    arrow-up
    6
    arrow-down
    5
    ·
    1 year ago

    If condition then this else that vs this ?? that

    Which option do you think requires less time for a person to identify and understand?

    Sure if it’s just your own code do whatever comes natural to you but there’s a reason we don’t use these kind of logical operators in day to day speech is my point.

    Ive been a backend dev for 2 years now and I’ve never come across the ?? operator and every time I come across a ternary operator I have to Google in what order comes what.

    Not saying it doesn’t make the code more concise and less “noisy” but sometimes a simple if else statement just makes the code easier to mantain

    • KairuByte@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      1 year ago

      It’s easier to mess up return a != null ? a : b than it is return a ?? b, and operators work from left to right.