L E F L I
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
ZILtoid1991@lemmy.world to Programmer Humor@programming.dev · 2 days ago

All Borrow Checkers Are Bastards (ABCAB - 12312)

lemmy.world

message-square
20
link
fedilink
157

All Borrow Checkers Are Bastards (ABCAB - 12312)

lemmy.world

ZILtoid1991@lemmy.world to Programmer Humor@programming.dev · 2 days ago
message-square
20
link
fedilink
  • flamingo_pinyata@sopuli.xyz
    link
    fedilink
    arrow-up
    54
    ·
    2 days ago

    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
      link
      fedilink
      English
      arrow-up
      29
      ·
      2 days ago

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

      • BitUnWise@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        24 hours ago

        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
      link
      fedilink
      arrow-up
      22
      arrow-down
      1
      ·
      2 days ago

      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
        link
        fedilink
        arrow-up
        9
        ·
        2 days ago

        Seems like someone doesn’t RAII their connections!

        • tias@discuss.tchncs.de
          link
          fedilink
          arrow-up
          12
          ·
          2 days ago

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

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

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

            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
              link
              fedilink
              arrow-up
              2
              ·
              edit-2
              1 day ago

              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”.

          • 𝙲𝚑𝚊𝚒𝚛𝚖𝚊𝚗 𝙼𝚎𝚘𝚠@programming.dev
            link
            fedilink
            arrow-up
            6
            ·
            2 days ago

            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
              link
              fedilink
              arrow-up
              5
              ·
              2 days ago

              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.

              • 𝙲𝚑𝚊𝚒𝚛𝚖𝚊𝚗 𝙼𝚎𝚘𝚠@programming.dev
                link
                fedilink
                arrow-up
                1
                ·
                22 hours ago

                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 :)

              • Zarobi@aussie.zone
                link
                fedilink
                English
                arrow-up
                0
                ·
                1 day ago

                You can make it a compilation error via configuration of project, but I forget exactly how to do it. Some magic Microsoft thing. I made it an error in my last project and fixed it up

                • FooBarrington@lemmy.world
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  1 day ago

                  https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html#MustDisposeResourceAttribute

                  This one, I’m guessing? At least that’s the one I know.

                  • Zarobi@aussie.zone
                    link
                    fedilink
                    English
                    arrow-up
                    0
                    ·
                    1 day ago

                    It was an editorconfig file thing, but navigating the docs on mobile phone is horrendous so I can’t easily find it

                    https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options

                    There’s much more than is listed on that page

    • [object Object]@lemmy.ca
      link
      fedilink
      arrow-up
      13
      ·
      2 days ago

      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.

      • Kacarott@aussie.zone
        link
        fedilink
        arrow-up
        22
        ·
        2 days ago

        when I’m the caller I sweat a little

        I too much prefer to send a text or email.

    • ZILtoid1991@lemmy.worldOP
      link
      fedilink
      arrow-up
      11
      ·
      2 days ago

      Police fans say the same thing about the police.

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
    • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1.06K users / day
  • 3.78K users / week
  • 7.07K users / month
  • 14.8K users / 6 months
  • 1 local subscriber
  • 33.5K subscribers
  • 2.41K Posts
  • 86.2K Comments
  • Modlog
  • mods:
  • Feyter@programming.dev
  • adr1an@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.19
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org