4 ms·
I surely prefer RAII to any garbage collection. It doesn't mean it's completely wrong though and has no uses at all. It's just of limited usefulness that's why
by shmerl 13y ago
I surely prefer RAII to any garbage collection. It doesn't mean it's completely wrong though and has no uses at all. It's just of limited usefulness that's why languages which overuse it claiming it's always needed (like Java) are too limiting. If anything, GC should be optional, not mandatory.
- AnimalMuppet 13y agoWell... if C and (early) C++ showed us anything, it's that programmers aren't very good at managing memory. (It's not just leaking memory. Accessing deleted memory is much worse.) So, what are you going to do? Just say "Most programmers are lousy, deal with it"? Introduce garbage collection, which solves 90% of the problem (memory) with no programmer intervention, but does nothing whatsoever to help the other 10% of cases (files, sockets, mutexes, etc.)? Rely on RAII, which in turn relies on programmer education and discipline? Or do you have another alternative? Optional GC could be interesting - maybe some kind of a switch that you set at compile time that says "this program uses GC" or "this program uses destructors". But then you're essentially talking about two similar, but different languages (like, say, Java and C++).
- shmerl 13y agoYou are right, in case of C++ the language doesn't ensure safety because of RAII since one can always go back to manual new / delete and etc. But in newer languages this can be avoided. Rust actually does that, and GC there is optional by the way.