

Java 7 : The new try-with-resources statement - budu
http://www.baptiste-wicht.com/2010/08/java-7-try-with-resources-statement/

======
mahmud
This is what happens when people aren't given UNWIND-PROTECT and DEFMACRO: a
cottage industry of pundits and legislators will form to discuss any itches
you might have, and whether to scratch them.

Watching Java programmers is like having a tribal shaman for a next-door
neighbor. You know it's none of your business, and you respect his beliefs,
but it's still unsettling to see him do one of those "hot knife in nose" and
"pull stubborn goat with nipple fish-hook" rituals.

Come to think of it, that last trick must be what Guy Steele did to drag C++
programmers "halfway to Lisp".

~~~
seertaak
So here we have a Lisp programmer -- with no apparent irony -- using the term
"cottage industry" in connection with Java.

> Watching Java programmers is like having a tribal shaman for a next-door
> neighbor.

This coming from the guys still harping on about the resplendent days of
unbridled hacker ecstasy in the Garden of Genera.

Pot. Kettle. Black.

~~~
mahmud
Why should there be an apparent irony? Lisp is a family of competing ideas and
implementations, this can be considered bad and a "cottage industry" in the
same way that the free market can be faulted for being "disparate solutions,
of various quality offered by a multitude of people and companies". IOW, not
bad at all; beauty is in the chaos.

With respect to Java, there is only one _real_ solution provider, and the
cottage industry is in the punditry that begs and supplicates to this sole
provider on behalf of various users and their respective interests. So Java is
more like the political lobbyists and lawyers.

Regarding Genera, dropping the G-word just marks one as long out of shape,
Lisp-wise. Lately, the fuss is all about JVM, CLR, multicore, large scale
distribution, packaging, semantic web, machine learning, mobile and
application platforms. You can even grow a beard and find nirvana on the JVM:

<http://common-lisp.net/project/armedbear/>

<http://clojure.org/>

~~~
seertaak
It's a bit trite to compare Lisp to the free market: it's not particularly
difficult for me to concoct the same metaphor for Java. ("The wealth of
libraries and frameworks, each vying for maximum use, exhibits emergent
patterns of creative destruction, similar to those prevalent in the free
market". See? Not that hard.)

It may be well true that there are more competing implementations of Lisp.
(Though that is also open to debate; after all, what is Android if not Java on
a new VM? What of OpenJDK?) And in any case, the great majority of Lisp
implementations are toy languages that lack the stability and features to be
used in any serious environment.

Your other points:

* If armed bear isn't dead, it definitely smells funny -- at least the last time I checked (~1.5 years ago).

* Clojure is cool in large part because it has access to the thousands of _Java_ libraries written by those shamen-like programmers you get such a kick out of mocking.

My point is that a programming language is just a tool to get something done.
Those that mock supposedly inferior languages miss the point that there are
aspects to those languages or environments that make them appealing for the
job at hand. If I want to do a web site, I'd use PHP with WordPress, because I
most likely won't have to write any code at all. If I want to write a web app,
I might use Ruby or Python. If I'm a real-time market trading platform, I'll
use Java because there's so much reliable, mature code out there and it's
really fast. If I want to write a music application or plugin, then I'm going
to need to use C++ to communicate with ASIO and VST.

And, finally, if I want to write a Lisp interpreter, I'll use Lisp ;)

~~~
mahmud
ABCL is far from dead. I hack on it and working on a Lisp SDK for Android.

My opinions are backed by code. I implemented this new Java feature in ~30
lines of CL, there was no committee involved:

[http://mahmud.arablug.org/java-try-with-resource-in-
lisp.htm...](http://mahmud.arablug.org/java-try-with-resource-in-lisp.html)

Something has to be said for expressiveness when one guy with an spare hour
can implement what might be considered a major language feature like this.
Makes you wonder what else is being made difficult by the language; how much
time and money, not to mention sanity, are being wasted trying to cut wood
with a dull knife?

------
ataggart

      (with-open [fis (FileInputStream. source)
                  fos (FileOutputStream. target)]
        (do-stuff fis fos))
    

I wish they would spend less time adding stuff to the Java language
(especially features present in other JVM languages), and more time fixing the
core API and improving the JVM feature set. Continuations would be nice.

------
Tichy
"java.lang.AutoCloseable interface"

Facepalm... (There has to be an easier way...)

~~~
wlievens
I'm sorry, but I fail to see what's wrong about that interface. It's perfectly
in keeping with the rest of the Java language. Usin duck typing would be a
horrible idea, since Java uses interfaces for type information on similar
syntactic sugar constructs (the for-each comes to mind).

Sure, one may or may not like Java, but if you're going to add this construct,
using an interface like that is the proper way.

~~~
Tichy
Sure, it just seems like horrible clutter. Yes, it is the spirit of Java - a
good reason to dislike the language.

This article actually made me realize Java is good if you have obsessive-
compulsive disorder. Now you can go through your code base and replace all
try/catch blocks with this pattern and neatly label your classes with another
interface/category. Then everything is in order again - you haven't gained in
productivity, but you have introduced more "system" into your world.

~~~
wlievens
I disagree with the view that introducing more "system" in the code is a waste
of time. I do agree with another poster in this thread, that it would be a lot
better if these kinds of constructs weren't baked into the language, but were
instead specified by macros.

------
fxtxrx
Is this similar to C#/.NET "using" construct ?

~~~
keltex
Yes, it's almost identical. One minor difference is that in C# you can't have
two different types in the same using statement. So you would have to nest two
using statements. In practice, this is rarely an issue.

------
nradov
Well sure it will help a little, but if only they would add control flow
closures then we could write these constructs ourselves rather than having to
build them into the core language.

