From: Edward Diener Date: 2001-11-25T03:58:29+09:00 Subject: [ruby-talk:26357] Re: [OT] Re: KDE or GNOME curiosity question... Yukihiro Matsumoto wrote: > Hi, > > In message "[ruby-talk:26285] Re: [OT] Re: KDE or GNOME curiosity question..." > on 01/11/24, Edward Diener writes: > > |> Ruby and many other languages with GC (Java is in the same boat) allow > |> resource finalization when the object is "destroyed". > | > |I am aware of that but unfortunately, like Java, one can't force the > |object to be "destroyed" a well-ordered point. > > I don't get the point. First of all, what does RAAI stand for? > Sorry, it should be RAII. It stands for "Resource Acquisition Is Initialization". The concept can be simply explained as a class which creates resources upon construction and releases those same resources upon destruction. "Resources" can of course be "memory" but may include many other things. In a GC system, where destruction is not ordered by the programmer but by the GC, it makes it difficult to use the above idiom in cases where "resource B" should only be acquired after "resource A" is released. > Second, are you claiming either following (a) or (b)? > > (a) resource finalization must occur when the object is recycled. > > (b) object reclamation must occur when the last reference to it is > removed. > For RAII, both need to be true. Essentially RAII relies on the scoping rules of a language to work properly, and the fact that when an object goes out of scope, it is automatically destroyed. > Ruby ensures (a), not (b). It's kinda hard to tell when the > reclamation happens. But I believe if you want to finalize > resource/object at certain point, you'd better to finalize it > explicitly. My objection to GC languages as they are currently designed. > If you don't care when, leave it to the garbage > collector. > > Plus, for explicit resource management, in Ruby, you can use the idiom > like > > open(path) do |f| > ... > end > > that ensures f to be closed at the end of the block. OK, my understanding of the use of block in Ruby is minimal since the documentation about them which I have from my download of Ruby for Windows seems poor. I will look at this as a possible solution to RAII design problems in Ruby. Thanks !