r/ProgrammerHumor • • Oct 12 '26

Meme stdModernizeMyCodebase

Post image
190 Upvotes

44 comments sorted by

View all comments

29

u/GabuEx Oct 13 '26

I feel like this picture really should be reversed to represent devs who for some weird-ass reason don't want to use the refcounted pointer types that make things way easier.

13

u/Valuable_Leopard_799 Oct 13 '26

A lot of people have a general repulsion to all types of garbage collection. So I at least understand not wanting the shared pointer a bit, but using unique pointer should cost you next to nothing and enforce a lot.

3

u/ForgedIronMadeIt Oct 13 '26

It took me a long while to come around to Java and its garbage collection back when it first came out, but I got over it eventually and now I'm considered an expert in Java by some folks I worked with, LOL. I still curmudgeonly advocate for more native code, but in a lot of use cases it is fine to have memory management.

3

u/Valuable_Leopard_799 Oct 13 '26

Many people seem to think that automatic memory management is a binary thing, "woe is me I now have no control".

After a while you discover you can tweak it, pause it, pre-allocate, write functions that don't allocate at all, play around with pointers, register destructors, redirect allocations to arenas, and work with the language to either allocate some objects in static memory or allocate them on the stack. All while allowing your less performance-sensitive logic to be much much simpler.

It's a deep world that almost nobody seems to want to get involved in.

1

u/ForgedIronMadeIt Oct 13 '26

Oh yeah. In a lot of cases you can get pretty similar performance out of a managed language without as much effort and today's hardware is so damn strong it can be hard to justify going with one over the other.

3

u/meneldal2 Oct 13 '26

The biggest issue I see with shared pointers or relying on garbage collection is it can be difficult to avoid bugs when you end up giving two different parts of the code write access to the same thing, or some part that doesn't know the stuff being pointed to just got changed.

0

u/Thecuriousserb Oct 13 '26

Unique pointer and other seemingly trivial types can fuck up your codegen and give you unoptimized assembly, chandler carruth from LLVM has many talks/slides that discuss this exact issue with unique ptr. Remember kids, there is no such thing as a zero-cost abstraction!

11

u/Fast-Satisfaction482 Oct 13 '26

That's such a straw man argument. Just because there may be cases where the hot spots of your software can benefit from using raw pointers doesn't mean it's reasonable to go bare metal in the whole code base.

3

u/Daemontatox Oct 13 '26

Oh wise one , how can one achieve perfect optimized and safe code

2

u/ilnarildarovuch Oct 13 '26

Using C and *Sans

1

u/the_horse_gamer Oct 13 '26

rewrite it in Rust Haskell

1

u/cheapcheap1 Oct 14 '26

How is unique_ptr not a zero cost abstraction? Is this anything other than compilers making avoidable optimization errors that will get fixed with time?

3

u/Thecuriousserb Oct 14 '26

Long story short unless you turn off exceptions, the stack unwinding code fucks up assembly for hot loops

14

u/ilnarildarovuch Oct 13 '26

Low level. RAII is good, but not for everything

3

u/_usr_nil Oct 13 '26

why not use C with a couple of libs then ?

6

u/ilnarildarovuch Oct 13 '26

Why not, but c++ is also possible to low level

1

u/Mojert Oct 14 '26

Congratulations, you now have a memory leak!

2

u/AstronomerStrange165 Oct 14 '26

Just don't leak memory.

1

u/ih-shah-may-ehl Oct 15 '26

I love refcounted pointers (esp when using COM) but for some win32 API stuff you sometimes need to do pointer arithmetic in blobs of data. There it's easier to use raw pointers while allowing the overal blob to be managed through a smart pointer