18 comments

log in to comment.

  • @flamingo_pinyata@sopuli.xyz · 6 Oct 2026

    The whole point of it is to prevent you from doing stupid shit. Yes it’s annoying. But you can’t handle memory management on your own, no matter how much you think you can.

    It’s either that or garbage collection. Choose which one you hate less.

    • @Sonotsugipaa@lemmy.dbzer0.com · 6 Oct 2026

      You’ll have to pry my ability to do stupid shit from my cold dead handsääääääää

      • @BitUnWise@programming.dev · 7 Oct 2026

        That’s what the unsafe keyword is for. HOW DARE THE BORROW CHECKER QUESTION MY DECISION TO RETURN A REFERENCE TO A TEMPORARY!

    • @tias@discuss.tchncs.de · 6 Oct 2026

      Garbage collection doesn’t solve the problem either, cause it’s too unpredictable and typically doesn’t even give you the option to close resources when memory is reclaimed. So just opening SQL connections and forgetting to close them will quickly drain the connection pool.

      • @RustyNova@lemmy.world · 6 Oct 2026

        Seems like someone doesn’t RAII their connections!

        • @tias@discuss.tchncs.de · 6 Oct 2026 · edited

          You can’t, not in e.g. Java or C#.

          C++ and Rust are the only languages I know of that do this right.

          • @ChairmanMeow@programming.dev · 6 Oct 2026

            It’s not impossible, at least in C# I know you can mark objects that need to be RAII with some custom attribute and enforce correct usage patterns with a custom analyzer. You need to write it yourself but it’s not impossible that way.

            • @tias@discuss.tchncs.de · 6 Oct 2026

              Maybe you’re thinking of IDisposable with the using keyword. The problem with that is that you have to remember to use it in every call site. Nothing stops a caller from writing var x = new Foo() and walking away.

              • @ChairmanMeow@programming.dev · 7 Oct 2026

                I am, but you can use a custom analyzer to stop it from compiling if misused. So you can actually stop a caller from writing that and walking away :)

          • @calcopiritus@lemmy.world · 7 Oct 2026

            You can do some kind of RAII in python with the with keyword. Only works for local variables though, where it’s easy to free resources manually

            • @tias@discuss.tchncs.de · 7 Oct 2026 · edited

              But if you ever forget the with keyword, you have a leak. With proper RAII the resource acquisition and release is a property of the object’s type and impossible to forget. RAII doesn’t just mean “resource acquisition is initialization”, it also implies “destruction is resource release”.

          • @WhyJiffie@sh.itjust.works · 8 Oct 2026

            java: try-with-resources, AutoClosable

          • @WhyJiffie@sh.itjust.works · 8 Oct 2026

            java: try-with-resources, AutoClosable

    • @panda_abyss@lemmy.ca · 6 Oct 2026

      I mean, I really like the zig approach. It usually turns into “the caller is responsible for managing the memory”

      But then when I’m the caller I sweat a little.

    • @ZILtoid1991@lemmy.worldOP · 6 Oct 2026

      Police fans say the same thing about the police.

  • @RustyNova@lemmy.world · 6 Oct 2026

    I don’t understand why people hate the borrow checker. Just make sure that you own the value until everything is done using it, or put it into a smart pointer

    • @Sunrosa@lemmy.world · 9 Oct 2026

      I basically never have borrow checker issues at all anymore, and smart pointers are basically never necessary. It takes getting used to, but it stops being an obstacle with practice.

      • @RustyNova@lemmy.world · 9 Oct 2026

        Yup. Although I like smart pointers due to their simplicity (unless it really needs performance), as well when dealing with tokio’s spawn (eww. Smol and future combinators are way better)

        Although trait bounds are always a bigger issue for me… probably because of my biblically accurate trait bounds