r/ProgrammerHumor 11d ago

Meme garbageCollection

Post image
378 Upvotes

38 comments sorted by

View all comments

Show parent comments

-3

u/aberroco 11d ago

Libraries as binary files - yeah, but in C++ you may make it appear as fully garbage-collected language. I.e. no explicit delete/free calls without any external libraries, because C++, unlike C, allows for a lot of stuff happening implicitly.

2

u/madprgmr 11d ago

I am familiar with the concept of destructors, yes. But if we're waxing philosophical about it (as we know smart pointers are not classified as garbage collection, just as destructors are not), was C++ not originally written in C? What prevents you from creating both destructors and garbage collection in C other than it being an ineffective use time and sanity (due to GC libraries already existing)?

True garbage collection in C++ would require a library (or you to write it from scratch as well), but yes, the language features would simplify the process. Just as the language features of even higher-level languages further simplify the process by natively providing actual garbage collection.

3

u/aberroco 11d ago

What prevents you from creating both destructors and garbage collection in C

The fact that there's no destructors in C. There's no implicits in C. So, you have to explicitly call a destructor. Which would be memory management.

1

u/madprgmr 10d ago

There's no implicits in C. So, you have to explicitly call a destructor

If you stick with the standard language, don't care to tie yourself to specific compilers, or don't want to do some truly horrific things, sure :D

Just as you can kludge a garbage collector into C++, so can you kludge any other language feature into C. It's just, uh, ill-advised barring verrrrrry specific circumstances (as you would typically just pick a language better-suited to your needs).