raganwald
(This is a snapshot of my old weblog. New posts and selected republished essays can be found at raganwald.com.)

Friday, March 07, 2008
  It's not just closures: Another Ruby idiom shows up in Java


There has been a recent flurry of posts discussing approaches to dealing with objects that aren’t there and methods that can’t be handled. Not to mention references back to implementing Monads as an alternative to explicit error-handling.

It’s all very refreshing, and valuable: Ruby is growing from the fringe. And it looks like the Java folks are listening: JSR-666 has added UnthrowableExceptions to its much-lauded SchödingerExceptions.

The proposed syntax is familiar to Ruby programmers:

yoda (UnsupportedEncodingException) {
String s = new String(byteArray, "UTF-8");
}

Hmmm… Is this something we’ve seen before?
 

Comments on “It's not just closures: Another Ruby idiom shows up in Java:
You realize JSR 666 is a joke, right?
 
It's dangerous to make jokes about programming languages: almost every parody feature you can think of has already been tried out seriously.Guy Steele, Jr.
 
try {
s = new String(byteArray, "UTF-8");
} catch (UnsupportedEncodingException e) {
}

That's a really nice example of where Java went wrong.
 
Not really, Reg...

The proposed yoda actually transforms checked exceptions which are not supposed to ever happen into runtime (unchecked) exceptions. It does not suppress them nor return values like Ruby's inline rescue does. (and, contrary to using an inline rescue, it's not supposed to ever happen)
 
The proposed yoda actually transforms checked exceptions which are not supposed to ever happen into runtime (unchecked) exceptions.

Oh dear this has become really serious. So is it sugar for try { ... } catch (UnsupportedEncodingException e) { throw new RuntimeError(e.getMessage()); }???
 
But this is no joke. Unreachable.

My buddy John Duimovich pointed it out to me in his blog post Yes, Virginia there is an Unreachable Clause.

The beauty of Unreachable, which I don't believe Ruby can touch at present:

Unreachable is a subtype of every type (even primitive types). No other type is a subtype of Unreachable. It is a compile-time error to convert null to Unreachable. It is an error to cast to the type Unreachable.
 




<< Home
Reg Braithwaite


Recent Writing
Homoiconic Technical Writing / raganwald.posterous.com

Books
What I‘ve Learned From Failure / Kestrels, Quirky Birds, and Hopeless Egocentricity

Share
rewrite_rails / andand / unfold.rb / string_to_proc.rb / dsl_and_let.rb / comprehension.rb / lazy_lists.rb

Beauty
IS-STRICTLY-EQUIVALENT-TO-A / Spaghetti-Western Coding / Golf is a good program spoiled / Programming conventions as signals / Not all functions should be object methods

The Not So Big Software Design / Writing programs for people to read / Why Why Functional Programming Matters Matters / But Y would I want to do a thing like this?

Work
The single most important thing you must do to improve your programming career / The Naïve Approach to Hiring People / No Disrespect / Take control of your interview / Three tips for getting a job through a recruiter / My favourite interview question

Management
Exception Handling in Software Development / What if powerful languages and idioms only work for small teams? / Bricks / Which theory fits the evidence? / Still failing, still learning / What I’ve learned from failure

Notation
The unary ampersand in Ruby / (1..100).inject(&:+) / The challenge of teaching yourself a programming language / The significance of the meta-circular interpreter / Block-Structured Javascript / Haskell, Ruby and Infinity / Closures and Higher-Order Functions

Opinion
Why Apple is more expensive than Amazon / Why we are the biggest obstacles to our own growth / Is software the documentation of business process mistakes? / We have lost control of the apparatus / What I’ve Learned From Sales I, II, III

Whimsey
The Narcissism of Small Code Differences / Billy Martin’s Technique for Managing his Manager / Three stories about The Tao / Programming Language Stories / Why You Need a Degree to Work For BigCo

History
06/04 / 07/04 / 08/04 / 09/04 / 10/04 / 11/04 / 12/04 / 01/05 / 02/05 / 03/05 / 04/05 / 06/05 / 07/05 / 08/05 / 09/05 / 10/05 / 11/05 / 01/06 / 02/06 / 03/06 / 04/06 / 05/06 / 06/06 / 07/06 / 08/06 / 09/06 / 10/06 / 11/06 / 12/06 / 01/07 / 02/07 / 03/07 / 04/07 / 05/07 / 06/07 / 07/07 / 08/07 / 09/07 / 10/07 / 11/07 / 12/07 / 01/08 / 02/08 / 03/08 / 04/08 / 05/08 / 06/08 / 07/08 /