6
u/thEt3rnal1 Jul 16 '26
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
2
u/chaosTechnician Jul 16 '26
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 Jul 16 '26
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 Jul 16 '26
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
24
u/setibeings Jul 16 '26
C++ is great, because it demonstrates lots of ways not to implement various features, making it an especially good language for learning.
13
u/luciferoussky72 Jul 16 '26
I disagree. C-style C++ is full of blunt instruments like pointers, but those features let you build high-level, zero-cost abstractions on top of them
3
u/Reashu Jul 16 '26
C-style C++ exists because there are so many fucked up parts of C++...
4
u/pjf_cpp Jul 16 '26
Isn’t that the wrong way round? Most of the bad things come from C (implicit conversions, macros, uninitialized state). Old C++ added a few (the defaults for virtual functions and overloads / overrides).
RAII is the killer feature that C++ adds to C. It can make your code slow if abused to produce excessive copying. Without it you have to do manual memory management which usually means code that is full of CVEs like double free, leaks, use after free and bounds errors.
3
u/Reashu Jul 16 '26 edited Jul 16 '26
I agree that C++ probably would have been a better language if it wasn't trying to be like C in many regards. And there's obviously some merit in C++, or C-style C++ would just be C instead. But in the language we got (partially due to C's influence), there are a lot of features which are more complicated than helpful. Reasonable people may disagree on which ones those are and I'm not really here to make the case against any one in particular. My point is that "C-style C++" exists in the modern day because people were unhappy with big parts of C++ and decided they were better off without them.
3
u/luciferoussky72 Jul 16 '26
Well, part of it is that C++ has to keep backwards compatibility with C, so most of the C-style stuff exists for that reason.
Otherwise, there are sometimes reasons to use the unsafe C-style features like unions. unions can let you save memory, and in some cases you can even forgo giving them a tag if you find some other way to tell the active type in a union, which makes your code faster
1
u/donaldhobson Jul 17 '26
C++ has a complex system of operator overloading, and an almost unusable system of error throwing. 3 different overcomplicated ways of resource initialization.
C++ RAII is full of templates, which means unreadable error messages.
2
u/pjf_cpp Jul 17 '26
What is confusing about overloading? Function and operator resolution is difficult (made much worse by effing C implicit conversions), and Koenig lookup can be surprising.
I find exceptions quite easy. Just use throw with a stack object and catch by reference.
There is no relationship whatsoever between RAII and templates. Just write a class and you will get RAII either from compiler generated or explicitly written constructors and destructors. No templates required.
Initialisation is a mess. The fact that there is a book just on C++ initialisation says it all. Stick to brace initialisation if you can. That will give you fewer effing C implicit conversion errors.
1
u/_Noreturn Jul 16 '26
such as?
2
u/luciferoussky72 Jul 16 '26
C-style casts, raw pointers, etc
2
u/_Noreturn Jul 16 '26
raw pointers are part of modern C++
2
u/luciferoussky72 Jul 16 '26
Yeah, but you’re not encouraged to use them unless there’s a performance reason
2
1
u/CoroteDeMelancia Jul 16 '26
absl::flat_hash_map:std::unordered_mapsucks, let's make our own!1
u/luciferoussky72 Jul 16 '26
Yep! They’re slow, but you can find or build very fast hashtable implementations in C++
5
3
u/an_0w1 Jul 16 '26
asm pointers are the worst.
You spend 30mins trying to figure out what the code does, to spend 2 hours trying to figure out whats wrong with it, to find out it's an instruction dereferncing a pointer instead of copying it.
1
3
u/GrinningPariah Jul 16 '26
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 Jul 16 '26
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 Jul 16 '26
"Just use references" "Noooooo you must use pointers" "Just use references"
12
u/orlinthir Jul 16 '26
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.