My point exactly. You're arguing for the sake of arguing.
No. You said that they were more or less one and the same
thing. They aren't, at least not in C++. They are basically
two distinct operations, which are in once special case invoked
by the same expression.
Irrelevant. Whether or not they are separate concepts reflects
nothing on the fact that separating their respective
occurences buys you nothing, or makes any sense.
Which doubtlessly explains why in C++ they are completely
separated into two separate functions, why in the STL (and every
other library of containers I've used) they are separate.
The fact remains that they are two separate concepts, and
combining to concerns in one action is never a good thing. It's
a violation of basic good design principles.
Not the ones that rely on garbage collection.
Where do you get that idea? In the Java projects I've worked
on, we've always considered object lifetime issues.
After all, if they did undertand the concept, they would
understand when their objects' lifetime has expired, and they
can be destroyed and their memory gets reclaimed.
Certainly. Anyone who can write correct code with garbage
collection can write it without, just as anyone who cannot write
correct code without garbage collection can't write it with.
That's never been in doubt. The difference is simply that if
you do know how to write correct code, it requires less work to
do so with garbage collection.
You seem to be carrying a misunderstanding that just because
an explicit class destructor is not required, it must mean
that the class destructor does not exist.
That, of course, is wrong. The class may, for example, contain
member objects that themselves have an explicit destructor.
Therefore, even if you do not need to code an explicit
destructor, it still, heavens-to-Betsy, exists. For the
obvious reasons.
You seem to be carrying a misunderstanding that people write
code at random, without doing any proper design first. And that
people will take an interface designed to fulfil one role in the
application, and use it to do something completely different.
Such techniques don't work. Garbage collection or not.
So you really can't just wash your hands of the whole matter,
by the virtue of claiming that you do not need to write a
destructor for your class. That's because there's always a
destructor, for every class. Just because you do not have to
explicitly define one, does not mean that the class destructor
does not exist. This does not excuse you from the
resposibility of properly implementing your object's lifetime,
and instead foisting it off on some sloppy garbage collector.
You don't seem to understand that good code is designed. It
doesn't just happen. (And again, garbage collection changes
nothing at that level.)
Generic garbage collection in the C++ context never takes form
of "well, you explicitly invoke the destructor when you
should, and I'll take care of releasing the memory at some
point later down the line".
Exactly. You invoke the destructor IF the object has
significant behavior which must be done at the end of its
lifetime. Otherwise, you don't bother. There are whole classes
of object types which by definition won't have significant
behavior which must be done at the end of their lifetime. There
are even object types which don't really have a defined
lifetime. And whether you invoke the destructor or not,
sometime later, WHEN no one else can access the object, the
memory it occupies will be reclaimed.
And that's a very big WHEN, because just because you've
destructed the object doesn't mean that no one else will access
it. With garbage collection, of course, you can verify that no
one does, and cause an assertion failure if they try to.
Without garbage collection, the memory may have been recycled,
and it's anyone's guess.
It's always "well, don't worry about the objects, when I
figure out they're no longer needed, I'll destroy them and
reclaim their memory".
Why do you keep repeating this, when it's been explained that it
is false. Garbage collection doesn't destruct anything, it just
reclaims memory which is otherwise inaccessible.
Brilliant. And when you figure out that no such pointers
exists, you're going to finally kiss it good-bye, right?
When no such pointers exist, no one can incorrecly access the no
longer existing object. So it no longer matters if the memory
image is there or not.
It's amazing how better this approach is, rather than just
using shared_ptr (or a better implemented alternative). Why
have to use such a bland concept like shared_ptr, when you can
use this wonderfully-convoluted object model?
Because shared_ptr doesn't work, and garbage collection does?
You certainly need a lot less code to write if you disclaim
the responsibility of properly tracking the objects' lifetime,
and foisting it off on some garbage collection algorithm.
It would help discussion if you'd at least try to be a little
bit honest. It's now been explained I don't know how many times
that garbage collection has nothing to do with object lifetime.
Except that it does allow detection of the error of accidentally
trying to access an object which no longer exists.
I would not call that "robust", by any stretch of imagination.
You call random (undefined) behavior more robust than detecting
programming errors?
Here's another hair to split, for you: _____________________
I'm not splitting hairs. The problem is that you just don't
seem to understand the basic C++ object mode, and the role
garbage collection plays in it.
Of course it's a tool. It's a tool for those who are too lazy,
or incompetent, to properly design their classes, and track
their instances' lifetime.
It's a tool for those who are too professional to artificially
create unnecessary work, just so that they can bill extra hours.
It's a tool for those who insist on robust software, with
serious error detection.
Your definition of "professional" does not seem to be the same
one as mine's.
I haven't figured yours out yet. Mine is simple: I develop
reliable and maintainable software, at the lowest possible cost
to my customer. Not using tools that effectively reduce my
workload and increase the reliability of the software would be
unprofessional, or even dishonest.
If I see someone's spaghetti code missing the obvious deletes,
in the appropriate places, I ask them about it, and they say
"oh, don't worry about, the garbage collector will take care
of it", I would not describe such a person as a
"professional".
In other words, the more deletes, the more professional.
Strange definition, to say the least.