• tatterdemalion@programming.dev
      link
      fedilink
      arrow-up
      2
      arrow-down
      1
      ·
      21 hours ago

      Sorry, I love Rust but I can’t really agree with you here. They only showed a macro_rules! definition, which is definitely rust syntax. Lifetime annotations are relatively common.

      I will concede that loop labels are incredibly rare though.

        • tatterdemalion@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          4 hours ago

          I guess I see what you mean if we want to get very technical about what a syntax extension is. But I think for the purpose of this discussion, it’s reasonable to think of macro_rules! as a part of the Rust language. Practically speaking, it is syntax provided by the language team, not just users of the language who are free to extend the syntax by using macro_rules! to do so.

      • fruitcantfly@programming.dev
        link
        fedilink
        arrow-up
        3
        ·
        20 hours ago

        Loop labels are rare, but they lead to much simpler/clearer code when you need them. Consider how you would implement this kind of loop in a language without loop variables:

        'outer: while (...) {
            'inner: while (...) {
                if (...) {
                    // this breaks out of the outer loop, not just the inner loop
                    break 'outer;
                }
            }
        
            // some code here
        }
        

        In C/C++ you’d need to do something like

        bool condition = false;
        while (...) {
            while (...) {
                if (...) {
                    condition = true;
                    break;
                }
            }
            if (condition) {
                break;
            }
        
            // some code here
        }
        

        Personally, I wouldn’t call it ugly, either, but that’s mostly a matter of taste

        • Ephera@lemmy.ml
          link
          fedilink
          English
          arrow-up
          1
          arrow-down
          1
          ·
          15 hours ago

          Well, you’d typically put the loops into a function and then do an explicit return to jump out of there. I believe, there’s some use-cases where this isn’t possible, which is why I’m cool with loop labels existing, but I’ve been coding Rust for seven years and have not needed them once…

    • wewbull@feddit.uk
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      4
      ·
      1 day ago

      What language are they then? They’re not Python, JS, <insert any other language here>

      • calcopiritus@lemmy.world
        link
        fedilink
        arrow-up
        7
        arrow-down
        1
        ·
        1 day ago

        You used macro_rules, which is not common at all. Most rust files don’t contain any macro definition.

        This code doesn’t even compile. There is a random function definition, and then there are loose statements not inside any code block.

        The loop is also annotated, which is not common at all, and when loops are annotated it’s a blessing for readability. Additionally, the loop (+annotation) is indented for some reason.

        And the loop doesn’t contain any codeblock. Just an opening bracket.

        Also, the function definition contains a lifetime annotation. While they are not uncommon, I wouldn’t say the average rust function contains them. Of course their frequency changes a lot depending on context, but in my experience most functions I write/read don’t have lifetime annotations at all.

        Yes, what you wrote somewhat resembles rust. But it is in no way average rust code.