Interesting how java is the only language included in the title, but the slides have the opinion that C#, Ruby and Python all suck as well. Seems like a cheap way to get upvotes.
Exception Safety, Garbage Collection etc. (a.k.a. Why Does Java Suck So Bad?)
11–20 of 72 posts
Re: Exception Safety, Garbage Collection etc. (a.k.a. Why Does Java Suck So Bad?)
#12I think you can avoid nesting finally thus: X x = null; Y y = null; try{ x = foo(); y = bar(); yadda(x,y); } finally { if (x!=null) x.dispose(); if (y!=null) y.dispose(); }
if (x != null) try { x.dipose(); } catch (Exception){} }
it's why the using keyword is so nice. Still, this is all hoops languages force us to deal with when they shouldn't (which is the OPs point)
Re: Exception Safety, Garbage Collection etc. (a.k.a. Why Does Java Suck So Bad?)
#13Interesting how java is the only language included in the title, but the slides have the opinion that C#, Ruby and Python all suck as well. Seems like a cheap way to get upvotes.
He sort of glosses over the "syntatic sugar" in C#. Which is simply: using(var resource = new Resource()) { // potential code that throws exception }
http://download.java.net/jdk7/docs/technotes/guides/language...
Re: Exception Safety, Garbage Collection etc. (a.k.a. Why Does Java Suck So Bad?)
#14...am I reading correctly that his argument for using C++/D (!) is that it's hard to remember to say this: try { mightFail(); } finally { doCleanup(); } instead of this: mightFail(); doCleanup();
Re: Exception Safety, Garbage Collection etc. (a.k.a. Why Does Java Suck So Bad?)
#15Earlier quoted context omitted.
He sort of glosses over the "syntatic sugar" in C#. Which is simply: using(var resource = new Resource()) { // potential code that throws exception }
Java finally (pun intended) gets a similar feature in Java 7 later this year: try-with-resources: http://download.java.net/jdk7/docs/technotes/guides/language...
Re: Exception Safety, Garbage Collection etc. (a.k.a. Why Does Java Suck So Bad?)
#16Earlier quoted context omitted.
And there actually is an idiomatic way to avoid the problem in Ruby: File.open("...") do |f| firstline = f.readline ... stuff that might throw an exception ... end If the "stuff" throws an exception, the file gets closed automatically. And while File is a library class, it's getting no special favors here --- any pure ruby library can easily implement similar APIs, and ActiveRecord's connection pool, for example, act…
Which counts as the sugar which he mentions. See also "using" in C#. These are pretty clearly design warts. WPF (C# UI library) jumps through some interesting hoops to make it look like all your resources can be properly garbage collected, but even then it tends to come back and bite you for any non-trivial application.
Re: Exception Safety, Garbage Collection etc. (a.k.a. Why Does Java Suck So Bad?)
#17I think you can avoid nesting finally thus: X x = null; Y y = null; try{ x = foo(); y = bar(); yadda(x,y); } finally { if (x!=null) x.dispose(); if (y!=null) y.dispose(); }
what happens if x.dispose() throws an exception? if (x != null) try { x.dipose(); } catch (Exception){} } it's why the using keyword is so nice. Still, this is all hoops languages force us to deal with when they shouldn't (which is the OPs point)
Re: Exception Safety, Garbage Collection etc. (a.k.a. Why Does Java Suck So Bad?)
#18Earlier quoted context omitted.
Java finally (pun intended) gets a similar feature in Java 7 later this year: try-with-resources: http://download.java.net/jdk7/docs/technotes/guides/language...
It's unclear to me why he says that the JDK7 addition doesn't really solve the problem. It seems to me that it is exactly this problem that ARM blocks are trying to solve. It's still not as clean as leveraging deconstructors when an object goes out of scope but it's much better than before.
The solution to this problem that makes sense to me is either conditions and restarts a la Common Lisp, or a type system that can handle multiple return values of different types in a sane way (e.g. return either a result or an error code and then pattern match against them) so that you don't always need to throw an exception in order to deal with an error.
Re: Exception Safety, Garbage Collection etc. (a.k.a. Why Does Java Suck So Bad?)
#19...am I reading correctly that his argument for using C++/D (!) is that it's hard to remember to say this: try { mightFail(); } finally { doCleanup(); } instead of this: mightFail(); doCleanup();
All in all, he's arguing for RAII, which is impossible in Java and a bunch of other popular languages.
Re: Exception Safety, Garbage Collection etc. (a.k.a. Why Does Java Suck So Bad?)
#20Earlier quoted context omitted.
what happens if x.dispose() throws an exception? if (x != null) try { x.dipose(); } catch (Exception){} } it's why the using keyword is so nice. Still, this is all hoops languages force us to deal with when they shouldn't (which is the OPs point)
You're lucky Java is checked at compile time. Ruby would eat that "no such method dipose" and silently leak x.
Not lucky enough, because x.dispose() could throw an unchecked exception.