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

    And no one on his team ever understood his code.

    Sometimes being declarative is better than being “smart”

    • PixxlMan@lemmy.world
      link
      fedilink
      arrow-up
      50
      arrow-down
      1
      ·
      1 year ago

      The last panel is infinitely more readable than parsing the whole chunk of logic above. Maybe you’re just not used to this language’s (I think this meme used C#) null operators.

    • herrvogel@lemmy.world
      link
      fedilink
      arrow-up
      38
      arrow-down
      4
      ·
      1 year ago

      Sure, if the rest of the team is first semester CS students doing their first group project. This is not an obscure 1337 h4x0r trick only known to programming gods writing COBOL code inside banking mainframes, it’s a simple operator.

    • merthyr1831@lemmy.world
      link
      fedilink
      arrow-up
      31
      arrow-down
      1
      ·
      1 year ago

      Sure, but null coalescing is a pretty common feature in modern languages. Once you know what ?? means you can apply it to a whole host of languages.

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

      I’m confused on how this is difficult to understand. Put aside the fact that it’s just a regular operator that… I mean virtually everyone should know, how hard is it to google “what does ?? mean in [language]” which has the added benefit of learning a new operator that can clean up your code?

      • DonnerWolfBach@feddit.de
        link
        fedilink
        arrow-up
        6
        arrow-down
        2
        ·
        1 year ago

        Well yeah but imagine you had to do that on most lines of the code? It would become very distracting imho. If you are in a team with people that have a lot experience and or will learn more anyway this is fine. But if you are in a team with not very good programmers which “will never learn” because they have other stuff to do, you should be careful when using code like this. Though I would prefer in the former of course.

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

          Honestly, and I mean this sincerely, if you’re on a team where the nullable coalesce is going to be confusing after the first handful of times encountered… look for a new job. It doesn’t bode well for their ability to do their jobs.

          This is like the guy at Walmart who needs hand holding each time they clean a machine, it’s a problem waiting to happen.

          • Zangoose@lemmy.world
            link
            fedilink
            English
            arrow-up
            2
            ·
            edit-2
            1 year ago

            Imo it’s context dependent. Obligatory “I’m only a college student/intern” out of the way.

            Whenever I’m working with a project with multiple languages (e.g. split frontend+backend, different connected services, etc.) operators like that can get blurry when they aren’t consistent between lancuages. Especially when one of those languages doesn’t have runtime type enforcement or has weird boolean behavior (looking at you JS/TS) which can lead to unintended behavior

            If everyone on the project is only working with that language, then your point is probably pretty close to the mark.

      • DudeDudenson@lemmings.world
        link
        fedilink
        arrow-up
        6
        arrow-down
        6
        ·
        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
          8
          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.

    • saumanahaii@lemm.ee
      link
      fedilink
      arrow-up
      13
      ·
      1 year ago

      This is why I favor 3. It’s fairly concise while not being all that obscure. And even if you’re not 100% on that syntax, context provides decent intuition about what it does.

    • RagingRobot@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      edit-2
      1 year ago

      This is why I usually don’t comment on stuff like this in PRs. If it’s readable and easy to understand it doesn’t need more abstractions. Even if it’s less code. What’s it save like a few bytes? That’s not as useful as the whole team instantly knowing how the code works when they see it lol

      I will say though if a jr dev came upon the last code they would just look it up and learn something so that’s a total valid path too. Just depends on your codebase and how your team works. I think it usually ends up being a mix with larger teams.

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

        There’s more to it imho. The first three are more prone to mistakes than the last. You are much less likely to accidentally alter the logic intended in a simple null coalesce than you are in if statements.

        • RagingRobot@lemmy.world
          link
          fedilink
          arrow-up
          1
          arrow-down
          1
          ·
          1 year ago

          That’s fair but if you had proper test coverage there wouldn’t be much risk. Who has that though? Lol

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

            None of my projects had time for reliable testing unfortunately. It was always “next sprint” or “when we have time” which never really came to fruition.

      • jhulten@infosec.pub
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        1 year ago

        Yeah, I think there is a tipping point between terse and magic. I might grimace a little at the first one, have no comment on the middle two, and definitely comment on the last one. Wrote code like the person troubleshooting it is on-call, mildly hung over, and it’s 3am.