
This way RAII is possible in D, which is very useful for things like scoped thread locks.įirst of all, Java does have destructors. Instead, when there are zero references to an object, the GC calls the destructor *immediately*, but deallocates the memory previously occupied by that object whenever it wishes (or it reuses that memory). > D did another thing right: it did not remove destructors, like Java did. and ANOTHER de-facto standard library called Tango, which looks a lot like a Java API and makes little use of D's more interesting features like metaprogramming, functional and generic programming crappy standard library called Phobos (getting better though) no multiple inheritance (which does make sense when using generic programming and metaprogramming just see policy-based design and the CRTP C++ technique for examples) lvalue return values (which would solve most of the operator overload problems) They also simplified the syntax, which is one of the major problems of C++.

This way RAII is possible in D, which is very useful for things like scoped thread locks. Functional languages all have a GC for a reason.ĭ did another thing right: it did not remove destructors, like Java did. Neither D nor C++ have them at the moment, but C++0x requires considerably more efforts to introduce them.

Now, once you have by-reference as default, things like closures get much easier to introduce. We could redefine the default behavior as "pass a reference of b to a", but who will then take care of the lifetime of b? Using a GC, this last question is handled trivially when the GC detects 0 references, b is discarded. The existence of shared_ptr, reference counting pointers etc. But, as said, the default behavior of assignment is "copy value". In 99.999% of all cases, you actually want a reference to an object, and not copy that object. While this is OK for primitive stuff, it is certainly not OK for complex types such as classes. a = b will always copy the contents of b to a. Somewhat less obvious is that a GC allows for by-reference assigments being the default.

This means that the GC can reuse previously allocated memory blocks, defragment memory transparently, automatically detect and elimitate leaks etc. The reason is simple: the GC has a global overview over all memory usage of the application (minus special stuff like OpenGL textures). The GC is the way to go for complex application.
