What, again?
Posted May 2, 2007 1:58 UTC (Wed) by
njs (subscriber, #40338)
In reply to:
What, again? by dcoutts
Parent article:
The Rise of Functional Languages (Linux Journal)
C++ actually does rather better than this (if used correctly) -- it's easy to use block scoping for most resource management (because, well, most resources of all kinds actually have lexical extent, at least in most programs when written well), and when a resource has dynamic extent, you use a smart pointer, which has explicit semantics about when it will be freed (i.e., exactly when the last reference disappears). Or you can do other fancier and situation-specific things if you want, of course, like pooled allocation.
There's no reason that other languages couldn't do this, but most GC languages are so hasty to ensure that the programmer does not *have* to worry about memory management that they remove the guarantees that the programmer needs in case they ever *want* to worry about memory management. So, in particular, most GC languages have either poor or no support for finalizers (cf. the weird interactions between Python's __del__ and the cycle collector, or the minimal guarantees Java makes about the environment in which a finalizer will be run), and make no promptness guarantees about collection. C++ is very very far from a perfect language, but it does get this part right -- you can always tell from code inspection exactly when each resource will be acquired and released.
(
Log in to post comments)