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

Programmer Humor

33524 readers
739 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
 
you are viewing a single comment's thread
view the rest of the comments
[–] ChairmanMeow@programming.dev 6 points 1 day ago (7 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 (6 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.

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

load more comments (2 replies)
load more comments (3 replies)
load more comments (3 replies)