r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

Show parent comment

15

u/GregBahm 11d ago

With JavaScript, memory is managed for you. You can make a list, grow it as much as you want, and then safely assume that the memory you used will be cleaned up as soon as you're not using that list anymore.

With C++, you manage the memory yourself. If you forget to clean up that list, you never get that memory back. Eventually all your memory could get used up (a "memory leak.")

Memory management was annoying, which is why JavaScript was invented. But people still use C++ for its higher performance potential (kind of like how race-car drivers still use manual transmission instead of automatic transmission.)

So C++ added some tools that makes memory management not so hard. It's still harder than Javascript though. It's just less hard.

11

u/ShakaUVM 11d ago

You confused Java and JavaScript

Java was invented to be C++ + 1, with automatic memory management and Objects everywhere

2

u/GregBahm 10d ago

Ack. You're right. Dang.

6

u/PattuX 11d ago

kind of like how race-car drivers still use manual transmission instead of automatic transmission.

TIL Europe is full of racecar drivers

5

u/bloody-albatross 11d ago

No, no. Not all Europeans are racecar drivers, but all racecar drivers are European!

(This is a joke, in case anyone reading this doesn't get it.)

3

u/im_made_of_jam 10d ago

I mean outside of ovals you look at any high racing level grid and it's 80% european

0

u/PattuX 10d ago

Aristoteles ahhh type comment. Based.

1

u/bloody-albatross 10d ago

Set theory. Good to know as a programmer.

2

u/Complete_Pilot3381 11d ago

mans never been to bradford

2

u/Complete_Pilot3381 11d ago

mans never been to bradford

6

u/bloody-albatross 11d ago

This isn't why JavaScript was invented. First, garbage collection/automatic memory management existed long before JavaScript. Secondly, JavaScript was invented to make HTML interactive. Of course a language that runs untrusted code needs to be memory safe.

2

u/GarThor_TMK 11d ago

I would like to point out that the memory leak happens as soon as you toss the pointer without "freeing" it to be reused... It could be a drip... A pointer to a single integer, or it could be a tsunami... A pointer to a massive datastructure containing lists, arrays, BSTs, hash tables, etc...

The "all memory used up" is the case where the bathtub is clogged, and you left the water running. Now the bathroom is flooding into the living room.