On Fri, Feb 22, 2008 at 4:56 AM, Nicola Musatti <[EMAIL PROTECTED]> wrote: > On Feb 22, 12:24 am, Carl Banks <[EMAIL PROTECTED]> wrote: > > On Feb 21, 1:22 pm, Nicola Musatti <[EMAIL PROTECTED]> wrote: > > > > > There are other downsides to garbage collection, as the fact that it > > > makes it harder to implement the Resource Acquisition Is > > > Initialization idiom, due to the lack of deterministic destruction. > > > > That's not a downside: it's at least a wash. > > > > In C++ you manage memory and the language manages resources. In > > Python you manage resources and the language manages memory. > > > > RAII is merely one way of minimizing complexity. Garbage collection > > is another way. > > In C++ memory is just another resource which you can handle just like > any other one, possibly using RAII. GC deals with memory very > reasonably, but makes it more complicate to deal with other resources. > There are many different kinds of resource and they have different optimal handling techniques. Memory in particular is really easily handled by GC - it's a resource that you can reclaim under pressure, so deferring it's collection and release makes sense, and it's even common these days for high quality GC to beat manual management in performance (never mind correctness). Other kinds of resource are much more timely, and require tight control over scopes, like mutexes and other locks. RAII is fantastic for these sort of things. Shared but limited resources like files work best with refcounting (closing a file that something else holds a reference to is usually an error).
Optimally, you would have a language that provides all three in easy, transparent ways. Python only provides two, but the first on is the least important so Python manages at least a B. C++ provides all 3, but importantly there's no language level enforcement of use, so you can (and people do, and this is a common source of bugs) accidentally bypass the mechanisms. If I had to use C++ these days, I'd use D instead. -- http://mail.python.org/mailman/listinfo/python-list