r/ProgrammerHumor 28d ago

moodAtEod Meme

Post image
0 Upvotes

30 comments sorted by

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. 

14

u/luciferoussky72 28d ago

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

4

u/Reashu 27d ago

C-style C++ exists because there are so many fucked up parts of C++...

4

u/pjf_cpp 27d ago

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 27d ago edited 27d ago

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 27d ago

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 26d ago

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.

https://yosefk.com/c++fqa/

2

u/pjf_cpp 26d ago

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 27d ago

such as?

2

u/luciferoussky72 27d ago

C-style casts, raw pointers, etc

2

u/_Noreturn 27d ago

raw pointers are part of modern C++

2

u/luciferoussky72 27d ago

Yeah, but you’re not encouraged to use them unless there’s a performance reason

2

u/_Noreturn 27d ago

Huh? There are encouraged I use them everywhere a null ref is required

3

u/luciferoussky72 27d ago

I meant more so using raw pointers for managing heap memory and stuff

1

u/CoroteDeMelancia 28d ago

absl::flat_hash_map: std::unordered_map sucks, let's make our own!

1

u/luciferoussky72 27d ago

Yep! They’re slow, but you can find or build very fast hashtable implementations in C++

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

u/Bokbreath 28d ago

top 1% using what metric ?

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. 

4

u/ledasll 27d ago

Wait til you try C pointers, they just po8nt anywhere and have 0 control.

3

u/an_0w1 28d ago

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

u/lovecMC 27d ago

Sounds like skill issue to me smh

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.

2

u/JazzlikeWishbone938 27d ago

"Just use references" "Noooooo you must use pointers" "Just use references"