The topic of the Rust experiment was just discussed at the annual Maintainers Summit. The consensus among the assembled developers is that Rust in the kernel is no longer experimental — it is now a core part of the kernel and is here to stay. So the “experimental” tag will be coming off. Congratulations are in order for all of the Rust for Linux team.

  • Buffalox@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    edit-2
    2 days ago

    I am willing to bet that the ownership paradigm that it enforces is going to feel at least moderately new to you

    Absolutely, I am more used to program closer to the iron mostly C. My favorite was 68000 Assembly, python is nice, but I prefer compiled languages for efficiency. Although that efficiency isn’t relevant for basic tasks anymore.

    The compiler error messages sound extremely cool. 👍

    • TriangleSpecialist@lemmy.world
      link
      fedilink
      arrow-up
      7
      ·
      2 days ago

      Ah, a fellow C coder. Never did do assembly with chips older than x86_64 basically. The only old school stuff I touched was writing an interpreter for the CHIP-8. I tried writing some CHIP-8 too, but coming from more recent paradigms, it seemed quite unwieldy to me.

      I like python for quick and dirty stuff, I don’t like python for being interpreted and it being not obvious what happens under the hood, memory wise, at a glance.

      Seeing as you do C I’ll say this. The one thing I really did not enjoy, subjectively, with Rust, is that writing “C-style loops” comes with a performance penalty because there are bound checks happening, so the idiomatic version of a loop in Rust usually involves iterators and function composition.

      I am stupid. C-loops are easy for me to understand. More sophisticated stuff is hard for my little brain. I’d rather be trusted with my memory access, and be reminded of my stupidity when comes the inevitable segfault. Keeps you humble.

      • HaraldvonBlauzahn@feddit.orgOP
        link
        fedilink
        arrow-up
        3
        ·
        2 days ago

        I like Python for quick and dirty stuff

        There is one more little secret that not everyone knows:

        You do not need lifetime annotations and full borrow checking if you do not care to press out the last drop of performance out of the CPU, or if you just draft experimental code.

        In fact, you can very much program in a style that is similar to python:

        • just pass function arguments as references, or make a copy (if you need to modify them)
        • just return copies of values you want to return.

        This makes your code less efficient, yes. But, it avoids to deal with the borrow checker before you really need it, because the copied values get an own life time. It will still be much faster than Python.

        This approach would not work for heavily concurrent, multi-threaded code. But not everyone needs Rust for that. There are other quality-of-life factors which make Rust interesting to use.

        … and of course it can’t beat Python for ease of use. But it is in a good place between Python and C++. A bit more difficult than Java, yes. But when you need to call into such code from Python, it is far easier than Java.

      • HaraldvonBlauzahn@feddit.orgOP
        link
        fedilink
        arrow-up
        4
        ·
        2 days ago

        The one thing I really did not enjoy, subjectively, with Rust, is that writing “C-style loops” comes with a performance penalty because there are bound checks happening, so the idiomatic version of a loop in Rust usually involves iterators and function composition.

        IIRC you can speed up such checks by putting an assertion in front that checks for the largest index - this will make repeated checks for smaller indices unnecessary. Also, bound checks are often not even visible on modern CPUs because speculative execution, branch prediction, and out-of-order execution. The CPU just assumes that the checks will succeed, and works on the next step.

        • TriangleSpecialist@lemmy.world
          link
          fedilink
          arrow-up
          4
          ·
          edit-2
          2 days ago

          I had no idea about the assertion! Thanks.

          Yes, this is plain wrong or often unimportant on modern architecture, you’re right. I, certainly mistakenly, thought this was one of the reasons for the idiomatic version involving function composition, which is the thing I, subjectively, don’t enjoy as much.

          I stand corrected.

          • HaraldvonBlauzahn@feddit.orgOP
            link
            fedilink
            arrow-up
            5
            ·
            2 days ago

            The function composition style comes from functional programming and Rust’s OCaml heritage. It can make it easier to reason about invriants and possible sets of values of the result of a computation step.

            Rust transforms these to the same or a close equivalent of hand-written loops.

            Similar methods are used in specialized, high-performance C++ libraries such as blitz++ and Eigen. But if you mess up bounds, you will get UB with them.

      • Buffalox@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        2 days ago

        it being not obvious what happens under the hood

        To me it feels like it does things I didn’t ask it to. So I’m not 100% in control 😋

        the idiomatic version of a loop in Rust usually involves iterators and function composition.

        What? You need to make a function to make a loop? That can’t be right???

        C-loops are easy for me to understand.

        Absolutely, the way C loops work is perfect. I’m not so fond of the syntax, but at least it’s logical in how it works.

        • Melmi@lemmy.blahaj.zone
          link
          fedilink
          English
          arrow-up
          2
          ·
          edit-2
          2 days ago

          If you don’t like the functional syntax you can usually use for each loops to the same effect.

          for element in array.iter() {
              println!("{element}");
          }
          
        • TriangleSpecialist@lemmy.world
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          2 days ago

          What? You need to make a function to make a loop? That can’t be right???

          Ah no, there is a misunderstanding. You can write C-loops, of course, they just could involve more work under the hood because in order to enforce memory safety, there needs to be some form of bounds checking that does not happen in C. Caveat: I don’t know whether that’s always true, and what the subtleties are. Maybe I’m wrong about that even, but what is true is that what I am about to say, you will encounter in Rust codebases.

          By function composition I meant in the mathematical sense. So, this example explains the gist of it. You may need to throw in a lambda function in there to actually do the job, yeah. I don’t know what the compiler actually reduces that to though.

          It’s just the more functional approach that you can also see with Haskell for example. I find it harder to parse, but that may be lack of training rather than intrinsic difficult.

          EDIT: pasted the wrong link to something totally irrelevant, fixed now