this post was submitted on 08 Jun 2024
1062 points (98.5% liked)

Programmer Humor

19488 readers
1081 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 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] xmunk@sh.itjust.works 80 points 5 months ago (43 children)

This graph cuts off early. Once you learn that pointers are a trap for noobs that you should avoid outside really specific circumstances the line crosses zero and goes back into normal land.

[–] lazyneet@programming.dev 16 points 5 months ago (15 children)

I've been using C++ almost daily for the past 7 years and I haven't found a use for shared_ptr, unique_ptr, etc. At what point does one stop being a noob?

[–] whou@lemmy.ml 7 points 5 months ago (1 children)

well, if I have an object on the heap and I want a lot of things to use it at the same time, a shared_ptr is the first thing I reach for. If I have an object on the heap and I want to enforce that no one else but the current scope can use it, I always reach for a unique_ptr. Of course, I know you know all of this, you have used it almost daily for 7 years.

In my vision, I could use a raw pointer, but I would have to worry about the lifetime of every object that uses it and make sure that it is safe. I would rather be safe that those bugs probably won't happen, and focus my thinking time on fixing other bugs. Not to mention that when using raw pointers the code might get more confusing, when I rather explicitly specify what I want the object lifetime to be just by using a smart pointer.

Of course, I don't really care how you code your stuff, if you are comfortable in it. Though I am interested in your point of view in this. I don't think I've come across many people that actually prefer using raw pointer on modern C++.

[–] lazyneet@programming.dev 2 points 5 months ago (1 children)

I just never learned smart pointers and write C++ code like it's C for aesthetic reasons.

[–] RecluseRamble@lemmy.dbzer0.com 3 points 5 months ago

Best to join a C++ community on some social media then. They'll tell you immediately why "C with classes" isn't C++.

load more comments (13 replies)
load more comments (40 replies)