• xenith@lemmy.ml
    link
    fedilink
    arrow-up
    6
    arrow-down
    1
    ·
    4 years ago

    As someone who knows no rust, what makes rust so appealing for writing the Linux kernel as opposed to all the languages that have existed since C++?

    • Ephera@lemmy.ml
      link
      fedilink
      arrow-up
      17
      arrow-down
      1
      ·
      4 years ago

      Well, most programming languages since C++ were just straight-up unusable in a kernel.

      The likes of Java, Python, Haskell need a kernel already up and running, so that they can start their virtual machine to execute your code.
      And even some languages that don’t need that, like Go, were unusable for kernel development, because you have basically no control over memory allocations.

      Ada probably failed to gain popularity in kernel development, because there were only proprietary compilers at first, so it never gained much mind share in the open-source community in general.

      And besides that, a large part of it was that C wasn’t that bad yet (in comparison to the then-modern programming languages).

      But Rust is also just really fucking good. We haven’t seen a low-level language with that much funding in decades. And it has a type system that rivals the most competent high-level languages (Haskell, OCaml, Scala etc.).

      In particular, it also promises to eradicate memory-related bugs which make up about 70% of vulnerabilities in the kernel.

      There’s also this post to the Linux Kernel Mailing List, which explains why or why not Rust (doesn’t compare it much to other languages): https://lkml.org/lkml/2021/4/14/1023

    • HMH@lemmy.ml
      link
      fedilink
      arrow-up
      11
      arrow-down
      1
      ·
      4 years ago

      Rust eliminates a lot of memory safety problems at compile time. Roughly speaking once you allocate memory and assign a variable to it, that variable “owns” said memory. A variable owning memory is responsible for its lifetime and just like in many other programming languages once it goes out of scope, the memory is released.

      So far so boring. What makes Rust different is the borrow checker. It ensures that all references (equivalent to pointers in C) to some memory (in this case not owned), are always valid. Like that it is impossible to access invalid blocks of memory in (safe) Rust. You never have to wonder who is responsible for deallocating memory and you never have to fear dangling pointers as those simply do not exist in Rust.

      I am sure there is much more to it, but this is certainly one of the arguments.

    • oldroad
      link
      fedilink
      arrow-up
      8
      arrow-down
      2
      ·
      4 years ago

      Mostly memory safety vs other systems languages. I’m not super knowledgable on the details as I’m a hobbyist pythonista, but I’ve been looking through the Rust book to slowly learn it for projects that might be better than using Python.

  • peppermint@lemmy.ml
    link
    fedilink
    arrow-up
    3
    ·
    4 years ago

    Linus in 2022: sorry guys, no releases this year, we’ve been chasing a runaway borrow around the kernel instead of facepalming unexpected memory allocation issues :D

  • Nevar@lemmy.ml
    link
    fedilink
    arrow-up
    1
    arrow-down
    2
    ·
    4 years ago

    Kotlin and Rust are going to run the world a decade from now.