Re: (Static) Constructors/Destructors in Ruby



PrimaryKey wrote:
Hello!

After reading the Pickaxe book I noticed it provides almost no
information about object lifecycle and no mention of destructors. As a
Java/C# guy my gut reaction was: Wouldn’t it be nice to have a
“unintialize” method to be called when the object is being destroyed?


Java does not have destructors either. finalize method is not guaranteed to be called


Another thing I find very surprising for a language having such a rich
OO model is the lack of static constructors (available in C# and somehow
in Java) and static destructors (something I always wanted to have in
Java/C#).

Ruby has them. Every class definition is an executable code (public, private, protected are methods) so you can alternate method definitions with arbitrary code (in fact, this is much more powerful mechanism than static blocks in Java and static constructors in C#)

lopex
.



Relevant Pages

  • Re: (Static) Constructors/Destructors in Ruby
    ... Java does not have destructors either. ... OO model is the lack of static constructors (available in C# and somehow ... Every class definition is an executable code (public, ...
    (comp.lang.ruby)
  • Re: finalize() not guaranteed to be called -- ever
    ... >> problem is that objects in variables have value semantics and not ... is also the justification for not including this possibility in Java. ... Just adding destructors ... You suggest that the JVM can just guarantee that finalize() is called, ...
    (comp.lang.java.programmer)
  • Re: CLOS and C++
    ... > time with the lack of destructors. ... as part of 2 you can point out that Java has no destructors. ... the new version of finalization that actually work. ... the Lispy equivalents are; certainly they are implementation ...
    (comp.lang.lisp)
  • Re: Class destructors
    ... The explanation I remember is destructors are generally used to free ... That's one of the things that bothers me about Java. ... the theory and science of your algorithms. ... reference to them have a one-to-one relationship destructors make sense. ...
    (comp.lang.java)
  • Re: finalize() not guaranteed to be called -- ever
    ... Then the Java object should have some kind of dispose method. ... It is very different in that it is possible to write C++ programs in which the destructors are never invoked manually but do run. ... C++ you can put objects on the heap as well and when you do the destructor is called manually using the delete statement. ... Either the object itself is stack based or you use a stack based object to invoke the ...
    (comp.lang.java.programmer)