All Borrow Checkers Are Bastards (ABCAB - 12312)

6 days ago by ZILtoid1991 to c/programmer_humor

flamingo_pinyata 58 points 6 days 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.

path: 0 26189892, hotness: undefined, score: 58, children: 20
Sonotsugipaa 30 points 6 days ago

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

path: 0 26189892 26191783, hotness: undefined, score: 30, children: 1
BitUnWise 3 points 5 days ago

That's what the unsafe keyword is for. HOW DARE THE BORROW CHECKER QUESTION MY DECISION TO RETURN A REFERENCE TO A TEMPORARY!

path: 0 26189892 26191783 26206945, hotness: undefined, score: 3, children: 0
tias 21 points 6 days 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.

path: 0 26189892 26190970, hotness: undefined, score: 21, children: 14
RustyNova 9 points 6 days ago

Seems like someone doesn't RAII their connections!

path: 0 26189892 26190970 26192141, hotness: undefined, score: 9, children: 13
tias 12 points 6 days 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.

path: 0 26189892 26190970 26192141 26192843, hotness: undefined, score: 12, children: 12
ChairmanMeow 6 points 6 days ago

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.

path: 0 26189892 26190970 26192141 26192843 26194063, hotness: undefined, score: 6, children: 7
WhyJiffie 1 point 4 days ago

java: try-with-resources, AutoClosable

path: 0 26189892 26190970 26192141 26192843 26237822, hotness: undefined, score: 1, children: 0
WhyJiffie 1 point 4 days ago

java: try-with-resources, AutoClosable

path: 0 26189892 26190970 26192141 26192843 26237839, hotness: undefined, score: 1, children: 0
calcopiritus 1 point 5 days ago

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

path: 0 26189892 26190970 26192141 26192843 26204648, hotness: undefined, score: 1, children: 1
panda_abyss 13 points 6 days 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.

path: 0 26189892 26190275, hotness: undefined, score: 13, children: 1
Kacarott 22 points 6 days ago

when I'm the caller I sweat a little

I too much prefer to send a text or email.

path: 0 26189892 26190275 26190800, hotness: undefined, score: 22, children: 0
ZILtoid1991 11 points 6 days ago

Police fans say the same thing about the police.

path: 0 26189892 26190629, hotness: undefined, score: 11, children: 0
RustyNova 33 points 6 days 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

path: 0 26189692, hotness: undefined, score: 33, children: 2
Sunrosa 1 point 3 days ago

I basically never have borrow checker issues at all anymore, and smart pointers are basically never necessary. It takes getting used to, but it stops being an obstacle with practice.

path: 0 26189692 26243766, hotness: undefined, score: 1, children: 1
RustyNova 1 point 3 days ago

Yup. Although I like smart pointers due to their simplicity (unless it really needs performance), as well when dealing with tokio's spawn (eww. Smol and future combinators are way better)

Although trait bounds are always a bigger issue for me... probably because of my biblically accurate trait bounds

path: 0 26189692 26243766 26247280, hotness: undefined, score: 1, children: 0
programmer_humor
programmer_humor

@programming.dev

login for more options
33571
2550
7101

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.

go to feed...