 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
mlw Guest
|
Posted: Fri Apr 20, 2007 4:10 am Post subject: Class destructors |
|
|
Could someone explain why there is no destructor in Java classes?
There are many times you need to be called WHEN an object goes out of scope
and not when it will eventally be freed. |
|
| Back to top |
|
 |
~kurt Guest
|
Posted: Fri Apr 20, 2007 6:28 am Post subject: Re: Class destructors |
|
|
mlw <mlw (AT) nospamnoway (DOT) zz> wrote:
| Quote: | 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.
- Kurt |
|
| Back to top |
|
 |
mlw Guest
|
Posted: Fri Apr 20, 2007 7:10 am Post subject: Re: Class destructors |
|
|
~kurt wrote:
| Quote: | mlw <mlw (AT) nospamnoway (DOT) zz> 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. |
|
| Back to top |
|
 |
~kurt Guest
|
Posted: Sat Apr 21, 2007 7:08 am Post subject: Re: Class destructors |
|
|
mlw <mlw (AT) nospamnoway (DOT) zz> wrote:
| Quote: |
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.
|
Most of my experience is with structured programming - OOD is relatively new
to me. I have to admit, I didn't start "getting it" until I started working
with Java. Most of the things you "can't" do, you can't do for a reason.
While I like C for structured programming, I just never liked C++ - seems
kind of like a kludge to me. Most of the C++ code I have been forced to work
with is just crap (fault of the programmer, not the language). Overall, I
have to admit I enjoy programming in Java. It seems to encourage better OOP.
You do need to have an idea as to what is going on under the hood to avoid
making bloated and inefficient code.
I've been coding up some engineering related algorithms to gain the
experience (not work related). I guess through using it I'll see if it is
really of any real value for scientific work. I did see a demo for a Java3D
based application similar to Google Earth (but with an astrodynamic slant).
It was very slick - excellent graphics and performance. I've also been
messing around with Java3D myself - so far I'm impressed.
- Kurt |
|
| Back to top |
|
 |
EricF Guest
|
Posted: Sat Apr 21, 2007 7:10 am Post subject: Re: Class destructors |
|
|
In article <duGdnaEi0J4EvLXbnZ2dnUVZ_q_inZ2d (AT) comcast (DOT) com>, mlw <mlw (AT) nospamnoway (DOT) zz> wrote:
| Quote: | ~kurt wrote:
mlw <mlw (AT) nospamnoway (DOT) zz> 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.
There are a large number of places running real and useful enterprise |
applications that were written in Java.
Being skilled in algorithms makes you a good developer. Java does nothing to
take away from that. Being skilled in Java "trivia" - aka the language and
"libraries" - makes you a better developer, but that's true of any language.
Java has its warts. Also true of all other languages I've seen.
Eric |
|
| Back to top |
|
 |
Silvio Bierman Guest
|
Posted: Tue May 01, 2007 5:08 pm Post subject: Re: Class destructors |
|
|
"mlw" <mlw (AT) nospamnoway (DOT) zz> wrote in message
news:duGdnaEi0J4EvLXbnZ2dnUVZ_q_inZ2d (AT) comcast (DOT) com...
| Quote: | ~kurt wrote:
mlw <mlw (AT) nospamnoway (DOT) zz> 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 |
|
| Back to top |
|
 |
~kurt Guest
|
Posted: Wed May 02, 2007 7:10 am Post subject: Re: Class destructors |
|
|
Silvio Bierman <sbierman@jambo-software.nl> wrote:
| Quote: |
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.
|
Thanks for the writeup.
- Kurt |
|
| Back to top |
|
 |
Faton Berisha Guest
|
Posted: Thu May 10, 2007 7:10 am Post subject: Re: Class destructors |
|
|
Silvio Bierman wrote:
| Quote: |
Total nonsense. Destructors have nothing whatever to do with general theory
and science of algorithms.
|
Well, for that matter, neither do constructors.
The reason for not implementing destructors in Java is,
I think, that many found it difficult to properly use them
(if not completely omit them), and this is compatible with not
implementing pointers.
Personally, the thing I miss the most from C++ is operator overloading.
(Readability is to blame here, I guess.)
Obviously, the designers had in mind things other than
developing a scientific computation or a system programming language
when designing Java.
Faton Berisha |
|
| Back to top |
|
 |
Silvio Bierman Guest
|
Posted: Thu May 10, 2007 4:19 pm Post subject: Re: Class destructors |
|
|
"Faton Berisha" <fberisha@uni-pr.edu> wrote in message
news:jOudnWNAmvxCCd_bnZ2dnUVZ8qLinZ2d (AT) giganews (DOT) com...
| Quote: | Silvio Bierman wrote:
Total nonsense. Destructors have nothing whatever to do with general
theory and science of algorithms.
Well, for that matter, neither do constructors.
|
Off course. Only a language as a whole represents a view on implementing
algorithms.
| Quote: |
The reason for not implementing destructors in Java is,
I think, that many found it difficult to properly use them
(if not completely omit them), and this is compatible with not
implementing pointers.
|
I already stated why a destructor is in contradiction with the Java language
logic. Java object references are quite close to pointers in C(++). Only the
concept-mix of arrays and pointers that C++ inherited from C (as much as
Stroustrup said to regret that) is totally missing which means no pointer
arithmetic.
Being an old time C (and since its early conception, C++) programmer I kind
of liked pointer arithmetic and I must admit I sometimes miss it when doing
some array fiddling in Java.
| Quote: | Personally, the thing I miss the most from C++ is operator overloading.
(Readability is to blame here, I guess.)
|
I welcomed it when it was added to C++ and used it enthousiasticly. In
retrospect I find it is only suitable when implementing very generic classes
(like strings, collection classes etc). I always found application level
logic to be expressed best with descriptively named operations
(functions/methods).
| Quote: | Obviously, the designers had in mind things other than
developing a scientific computation or a system programming language
when designing Java.
|
My guess is they started with C++ but wanted something managed (Virtual
Machine based) and simpler (quirk-free as opposed to C++ which is full of
quirks that only language theorists like to play with). They made some good
design decisions, some bad. The resultng Java environment just works,
despite some things I would like to have seen different about the language.
The cross-platformness and the enormous amount of freely availably libraries
for almost anything a developer could need in combination with an OK
language has effectively won me over.
I find it pointless to discuss isolated language details or doing
apples/oranges comparisons between programming languages. In the end the
quality and timely availability of the resulting software systems is all
that counts, whichever languages where used to implement them.
Silvio Bierman
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|