You're making it seem as if __I__'m the one who started this endless debate when it was in fact you that took me up on a point I made about Java, the supposed C++ killer. I simply stated that C++ does RAII while Java doesn't, to which you responded with some irrelevant talk about garbage collection and the following statement:
I wasn't talking about RAII. I was talking about the language in general. If I didn't make that clear, I apologize.
which is ironic, given that RAII is both a convenient and powerful tool ... that Java doesn't have. Anyway, to get back to the point I'm not saying that C++ is the one true language for every task or even that you shouldn't use Java; all I'm saying is that for a supposed C++ killer language to lack such a fundamentally useful feature is certainly a disappointment.
said Java was a "C++ killer". You may have heard that somewhere, but I never have, and I certainly wouldn't agree with such an obvious absurdity. You, my friend, have created a false dilemma.
Having said that, all of the memory managed languages taken together (Java, C#, PHP, Perl, Ruby, etc.) have really cut into the potential C/C++ code inventory, because they do what many programmers need them to do, without requiring programmers to mess with stuff they don't need to mess with.
Not in Java, nope. The memory of the class object representing a database connection will be properly freed by the garbage collector, but the actual database connection will not necessarily get closed because that would require your finalize() method to run, and the garbage collector gives you ZIP guarantees as to WHEN or even IF that will happen. Linky -> Practical Java Praxis 67: Do Not Rely on finalize Methods for Nonmemory Resource Cleanup
Thanks for linking to an article describing what I was talking about. Now go back and re-read what I wrote.
Did you re-read it? Jeepers -- how dumb do you think I am!? Of course you can't rely on the garbage collector to run Finalize(). That's why you use try-catch-finally. And that's precisely what I meant when I wrote: "Even in Java you can write code to guarantee network and OS resource release, though you can't get the reference variables de-allocated right away." IOW, there are well known and easy to implement design patterns for resource control, even if they don't rely on the holy RAII.
Actually yes, I do. And the software we write is safety-critical, which is why mechanisms that eliminate or reduce potential sources of errors are extremely important to us. Apart from the fact that eliminating error sources should be a prime goal of ANY programmer worth his salt.
Since you want to go there, any programmer "worth his salt" knows that any desired but non-existent language feature can be synthesised. The smart pointer you demonstrated earlier is a pointer synthesized into an object through encapsulation. By the same token, safe resource management can be synthesized by writing the necessary logic into wrapper code encapsulating an unsafe class in a safe one. No big deal -- it's done every day.
WRT your professional endeavors, here's a piece of unsolicited but valuable advice: don't fall in love with any particularl language, much less any particular language feature. You're going to have to say goodbye to your present job someday, and if you insist on working within a narrow selection of technologies, you're just making yourself unmarketable.
Edited by aevans, 31 May 2010 - 1335 PM.