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.
You’ll have to pry my ability to do stupid shit from my cold dead handsääääääää
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.
Seems like someone doesn’t RAII their connections!
You can’t, not in e.g. Java or C#.
C++ and Rust are the only languages I know of that do this right.
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.
Maybe you’re thinking of
IDisposablewith theusingkeyword. The problem with that is that you have to remember to use it in every call site. Nothing stops a caller from writingvar x = new Foo()and walking away.
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.
when I’m the caller I sweat a little
I too much prefer to send a text or email.
Police fans say the same thing about the police.
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




