Hacker News new | comments | show | ask | jobs | submit login
Java 7 : The new try-with-resources statement (baptiste-wicht.com)
17 points by budu on Aug 24, 2010 | hide | past | web | favorite | 19 comments

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".

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.

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:



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 ;)

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:


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?

  (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.

"java.lang.AutoCloseable interface"

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

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.

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.

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.

duck typing


I'm not a lisper, how does a macro allow you to close many different types of closable things, even when you don't know up front all types of closable things?

Thanks. Isn't it defgeneric that is allowing you to open and close different types of things without knowing about them in advance, not the macro?

All we need to do this is duck typing and closures I believe.

Yes, defgeneric is.

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

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.

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.

Applications are open for YC Summer 2018

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact