Google-apps
Hoofdmenu

Post a Comment On: Ushanka

"When goodbyes aren't enough..."

4 Comments -

1 – 4 of 4
Blogger John Zabroski said...

I understood almost everything in your blog post. However, what do you mean by, "And it's coming back!"? This sentence jarred me quite a bit, and I couldn't comprehend what you meant here.

You write very well, by the way.

February 8, 2008 at 5:57 p.m.

Blogger sharvil said...

Thanks for the comment! What I mean by that is that the resource we just attempted to release is still making demands of the caller (catch IOException) after the caller has said, "You no longer exist in my eyes."

It's not possible to just ignore the resource as soon as we call r.close(). The resource has an impact on the code after the call to close.

February 10, 2008 at 3:48 p.m.

Blogger Mark Mahieu said...

There are a number of proposals which aim to make this much easier (and safer) in a future version of Java:

'ARM blocks' are specifically aimed at this problem. There's a prototype available here.
'BGGA' Closures deal with this in a different way, and have a much wider scope. Follow that link for a prototype too.
JCA takes a similar approach to BGGA, but there's no prototype of this functionality yet.

March 2, 2008 at 4:30 p.m.

Blogger sharvil said...

Thanks for those links, Mark. While ARM blocks solves the problem in the short-term by adding syntactic elements to the language, I don't think it tackles the real issue: poor API design.

The point is that the API designer isn't thinking about the intent of the caller. Rather, the designer is (probably) thinking, "exceptions are for error reporting" and applies that blindly without considering the consequences or what the caller is implicitly telling you.

I would be better to see closures being passed around in these scenarios. It preserves the control flow in the caller but the point still remains: handling errors on close should be optional and the API designer must be responsible enough to think about the caller's intent.

March 5, 2008 at 7:06 p.m.

You can use some HTML tags, such as <b>, <i>, <a>

You will be asked to sign in after submitting your comment.
Please prove you're not a robot