• flamingo_pinyata@sopuli.xyz
    link
    fedilink
    arrow-up
    34
    ·
    12 hours 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.

    • tias@discuss.tchncs.de
      link
      fedilink
      arrow-up
      14
      arrow-down
      1
      ·
      10 hours 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.

        • tias@discuss.tchncs.de
          link
          fedilink
          arrow-up
          9
          ·
          9 hours 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.

            • tias@discuss.tchncs.de
              link
              fedilink
              arrow-up
              4
              ·
              5 hours 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.

    • [object Object]@lemmy.ca
      link
      fedilink
      arrow-up
      10
      ·
      11 hours 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.