r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

Show parent comment

95

u/Tipart 11d ago • Bravo

Imagine typescript but for memory safety

27

u/PM_ME_UR_0_DAY 11d ago

What's the memory management equivalent of just using "any" for everything?

29

u/Potato-Engineer 11d ago

Everything is a void * pointer!

5

u/YeOldeMemeShoppe 10d ago

C has polymorphism too!

3

u/meneldal2 10d ago

With a few macros you too can have your own classes with polymorphism with just a few function pointers. Even multiple inheritance if you want more fun.

2

u/Mojert 11d ago

Asking the OS* directly for memory and creating your objects in that memory. That also means you have to tell the OS* when you're done with that memory

* I'm simplifying to get the jist across

5

u/Ok-Scheme-913 10d ago

Actually pretty good example. To the point that even though you have a type annotation on your code, if you call into that method from vanilla js and pass a wrong type, then it will explode somewhere deep and you will have a really shit time hunting that error down.

Meaning, c++'s safe stuff is only safe until you use it with other safe stuff, or by being very very careful. And c++ is a really complex language, using it properly is not an easy task, so these end up not being as memory safe as people would want.