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

    What’s wrong with this? I don’t get it. Perfectly understandable code to me. Can someone explain?

    • Err(()).unwrap()@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      Looks a lot like more syntax sugar to me, to hide boilerplate code. It’s not necessarily a bad thing, but it can obfuscate the actual meaning of the code for the sake of brevity. What does A ??= B do at a glance, for example?

      It’s not exclusive to C# or “corporate” languages either. Rust has a fuckton of syntax sugar that makes it difficult to read.

        • Err(()).unwrap()@lemmy.world
          link
          fedilink
          arrow-up
          0
          arrow-down
          1
          ·
          1 year ago

          And that improves readability, how? Don’t get me wrong, I’m a big fan of the Elvis operator, but chaining multiple null coalescing assignments into a one-line expression is a chore to decipher.

          By the way, you forgot to return the result.

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

            you forgot to return the result.

            What result? The result is A being assigned a value. That’s the result.

          • masterspace@lemmy.ca
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 year ago

            And that improves readability, how?

            Because null checks are an extremely common operation to have to do, and this let’s your code read as just the business logic without these constant null checks breaking things up by multiple lines.

            It’s only not readable to you because you’re not used to them. That’s the case for literally every bit of new programming syntax that comes along.

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

              Exactly. Not adding efficient things because “they will be new” is just silly. We adapt, as programmers. We learned the language a first time, so we know what it means to learn things. Just like in English when you come upon a word you don’t understand, either you understand it by its context, or you just look it up. Simple as that.

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

            And that improves readability, how?

            By being used to it. As many have said, if you’re familiar with the syntax you have no problem parsing this.