this post was submitted on 06 Oct 2026
156 points (95.9% liked)

Programmer Humor

33524 readers
790 users here now

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

founded 3 years ago
MODERATORS
 
top 20 comments
sorted by: hot top controversial new old
[–] flamingo_pinyata@sopuli.xyz 51 points 1 day ago (4 children)

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 28 points 1 day ago (1 children)

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

[–] BitUnWise@programming.dev 2 points 10 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 21 points 1 day ago (1 children)

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 9 points 1 day ago (1 children)

Seems like someone doesn't RAII their connections!

[–] tias@discuss.tchncs.de 12 points 1 day ago* (last edited 1 day ago) (2 children)

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 1 points 15 hours ago (1 children)

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 2 points 14 hours ago* (last edited 11 hours 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".

[–] ChairmanMeow@programming.dev 6 points 1 day ago (1 children)

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 5 points 1 day ago (2 children)

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 1 points 9 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 0 points 12 hours ago (1 children)

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 2 points 11 hours ago (1 children)
[–] Zarobi@aussie.zone 0 points 11 hours ago (1 children)

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

[–] FooBarrington@lemmy.world 2 points 9 hours ago (1 children)

The editorconfig rules you're referencing can turn code analyzer warnings into errors, but you still need a code analyzer to actually trigger the error.

[–] Zarobi@aussie.zone 0 points 9 hours ago

Yeah I remember that project used Visual Studio on Windows. I'm not sure if it works outside of that environment

[–] panda_abyss@lemmy.ca 13 points 1 day ago (1 children)

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 22 points 1 day ago

when I'm the caller I sweat a little

I too much prefer to send a text or email.

[–] ZILtoid1991@lemmy.world 11 points 1 day ago

Police fans say the same thing about the police.

[–] RustyNova@lemmy.world 30 points 1 day ago

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