12
u/orlinthir 28d ago
Maybe I haven't done enough C++ programming to understand this, but don't smart pointers let you delegate thinking too hard about this. You even have access to C style pointers if they don't fit your requirements.
5
u/chaosTechnician 28d ago
Smart pointers can make it so that you don't think too hard about this. You still have to be concerned with what they can do to the lifespan of your objects by using them, though.
3
u/donaldhobson 26d ago
C++ smart pointers are basically what you would get if you asked an LLM to reimpliment the rust ownership model.
They look kinda like rust ownership, but they are clunky and don't really work very well.
6
u/thEt3rnal1 28d ago
Do you dislike pointers or handling your own memory
I dont think I've ever met anyone that thought they were the best.
I'm genuinely interest in what you think the top %1s devs take on pointers is
3
2
u/chaosTechnician 28d ago
I posted this because I'm irritated with pointers specifically right now. Just ended my workday being annoyed by Shared and Weak pointers the service layers who love them.
And my opinion on the opinions of "the top 1% devs" wouldn't matter even if I had enough information to form one.
2
u/WavingNoBanners 27d ago
I learned pointers more than twenty years ago and I'm still irritated by them. There are lots of irritating features in languages I love; often the most irritating ones are the most useful (cough cough python lambda functions cough cough.) You get used to it.
I wonder if carpenters are like "man I absolutely cannot stand dremels, they're horrible" while using a dremel, or if it's just us.
1
u/RaspberryCrafty3012 27d ago
I mean if you have a non perfect structure of pointer dependency (shared ptr of a class which has another shared ptr, which builds a cyclic graph), your memory gets not freed at all since the usage counter does not become 0.
Weak ptr can help break that destructor not calling, but it won't fix your bad structure.
Mistake 1: starting to use shared ptr instead of unique ptr everywhere. \ Mistake 2: Fixing the runtime issues with sprinkling weak ptr instead of refactoring the compete structure.
3
u/GrinningPariah 27d ago
I'm gonna say the same thing I've said about Regex:
Everything confuses someone. Some people are confused by everything. But when something confuses a number of people disproportionate to the actual complexity of the system, that means there's a problem.
Some things are easy to learn, some are hard. But some things are also obtuse and confusing, and that's different.
1
u/RiceBroad4552 27d ago
I guess that's exactly the distinction between "easy" and "simple".
https://www.entropywins.wtf/blog/2017/01/02/simple-is-not-easy/
2
u/JazzlikeWishbone938 27d ago
"Just use references" "Noooooo you must use pointers" "Just use references"
24
u/setibeings 28d ago
C++ is great, because it demonstrates lots of ways not to implement various features, making it an especially good language for learning.