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
- 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.
founded 3 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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.
You can do some kind of RAII in python with the
withkeyword. Only works for local variables though, where it's easy to free resources manuallyBut if you ever forget the
withkeyword, 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".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 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 :)
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
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.
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
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.
Yeah I remember that project used Visual Studio on Windows. I'm not sure if it works outside of that environment