Re: Class destructors
- From: "Silvio Bierman" <sbierman@xxxxxxxxxxxxxxxxx>
- Date: Tue, 1 May 2007 14:08:06 +0200
"mlw" <mlw@xxxxxxxxxxxxxx> wrote in message
news:duGdnaEi0J4EvLXbnZ2dnUVZ_q_inZ2d@xxxxxxxxxxxxxx
~kurt wrote:
mlw <mlw@xxxxxxxxxxxxxx> wrote:
Could someone explain why there is no destructor in Java classes?
The explanation I remember is destructors are generally used to free
memory, and Java has garbage collection. Doesn't make it right, but that
is the way it is.
That's one of the things that bothers me about Java. So many newbe CompSci
people think it is wonderful, but it has so many glaring omissions and all
too often it falls short of a real and useful programing language. Like
Windows, skill in Java comes from knowing the trivia of Java, and not from
the theory and science of your algorithms.
Total nonsense. Destructors have nothing whatever to do with general theory
and science of algorithms.
In the C++ object model where objects (class instances) and the lexical
reference to them have a one-to-one relationship destructors make sense. The
fact that C++ does not offer GC makes them even essential. And yes, many
other usefull constructs can be expressed using destructors.
In Java (and most other contemporary programming/scripting languages) the
object instance and the syntactical construct referencing it are loosely
coupled. Objects can have zero or more references pointing to them, not
unlike C++ pointers (or C++ references, for that matter). Such an object
model does not allow the definition of a destructor like construct because
the lexical scope of an object reference and the lifetime of the actual
object instance are at best indirectly related.
If you value a theoretical approach to programming than you should be able
to distinguish abstract algorithms from language constructs that allow you
to implement them. If you find yourself unable to implement your abstract
algorithm in a language without destructors (which would not leave you many
options anyway) then you obviously are unable to make that distinction.
Silvio Bierman
.
- Follow-Ups:
- Re: Class destructors
- From: Faton Berisha
- Re: Class destructors
- Next by Date: How to write Array of Object to a file?
- Next by thread: Re: Class destructors
- Index(es):
Relevant Pages
|
|