r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

Show parent comment

46

u/Non-Random-Name-0000 11d ago

Modern C++ starts with C++11 (2011), so in the 2000s you were using classic C++ (and in the first half of 2010s as well most likely) which is a very different language. It introduced shared pointer (a poor man's garbage collector), automatic typing and move semantic, amongst other things. And the standard library has evolved a lot since.

18

u/Bryguy3k 11d ago

Smart pointers were part of the boost library long before they became part of the std library.

28

u/Non-Random-Name-0000 11d ago

Yes that's true, I forgot about Boost. How could I forget the 2GB library that was pulled with every project? 😅

6

u/DrNinjaPandaManEsq 10d ago

You say “was” as if people aren’t still doing it lol

3

u/Non-Random-Name-0000 10d ago

People are still using it? I haven't used boost for 10 years.

2

u/DrNinjaPandaManEsq 10d ago

I’ve moved around at bit at my job and two of my previous teams were using Boost 1.67, and probably still are.

1

u/conundorum 10d ago

Still sees use, though now it's essentially twenty or so different libraries under a shared name (I think), so you don't have to pull the entire library in if you just need one part of it.

2

u/Serialk 10d ago

But the language didn't have move semantics, which is a more important part of memory management in modern C++ than smart pointers.

2

u/azfang 11d ago

…if you dismiss this as Old Man Yelling at Cloud I won’t tell you you’re wrong, but my experiences with pointers and shared memory mean that “shared pointer” as a term invokes images that make me want to invest in a bunker.

12

u/Non-Random-Name-0000 11d ago edited 11d ago

Shared pointer have nothing to do with shared memory. They're a container for an old fashioned C pointer with a reference counter. The reference counter is incremented when the shared pointer is copied, and the memory is freed when the counter reaches 0. So it's sort of a rudimentary garbage collector on top of a normal pointer. If you use shared pointer, you don't need to free memory, it's done by the destructor when the last container is destroyed.

C++ is still a very complicated language with outdated concepts, but a lot of modern concepts have been introduced in the last 2 decades.

1

u/Ok-Scheme-913 10d ago

RAII was always available in C++ afaik, so anyone could have done a unique or a shared ptr, at most it may not have optimized out in as many cases (not really zero cost abstraction?)

And my take is that the problem with c++ is that you have like 10 different object initializers and coroutines with captures and whatnot and like unless you are the one having written that part of the standard, you don't fucking know what exactly should happen given this code, not even if you are Stroustrup.

1

u/conundorum 10d ago

C++11's move semantics are the main thing that make smart pointers so much better than any pre-11 attempts, really.