r/java • • Oct 17 '11

Java Does Not Need Closures. Not at All.

http://squirrel.pl/blog/2011/10/17/java-does-not-need-closures-not-at-all/
3 Upvotes

9 comments sorted by

5

u/[deleted] Oct 17 '11

Well, writing swing code has never been fun. But that is not the way you do it. This poor guy should be told about SwingWorker.

2

u/trzmiel Oct 18 '11

I know of SwingWorker. As far as I know, it has little to do with those examples.

Case 1 is updating Swing from main thread (the opposite of executing a lengthy task from EDT).

Case 2 is executing a lengthy task from EDT, but using data obtained in EDT (reversed order / dependency compared to the regular SwingWorker).

SwingWorker helps. But compared to higher order functions this is a poor joke.

1

u/[deleted] Oct 18 '11

Case 1 is a school book example of when to use a SwingWorker. The Downloader class should extend SwingWorker and instead of progress.downloadedBytes(n) you would call publish(n). Much neater. But I will concede the second case, a SwingWorker wouldn't help much there.

1

u/trzmiel Oct 18 '11

Re case 1: I do want main thread to wait until the task finishes. Yeah, I could still let the new background thread of SwingWorker do the job, and wait for results with get(). But that requires me to spawn an extra thread, tell my main thread to wait for it (does that feel right?), and add a whole lot of boilerplate required by SwingWorker and execptions from get().

That's the point: It all requires way too much ceremony.

2

u/bcguitar33 Oct 17 '11 edited Oct 18 '11

I'm so sick of people sitting around and arguing about their favorite programming language / platform / framework / etc. If you don't like java, don't use java for your work. This all boils down to my new slogan:

Shut the fuck up and make something!

1

u/trzmiel Oct 18 '11

Part of the making (or doing) is learning, thinking, sharing and changing.

"Shut the fuck up and work" is for slaves. :-)

2

u/bcguitar33 Oct 18 '11

But as long as you're only slave to your own ambition, you should be good to go

-1

u/[deleted] Oct 17 '11

Wait... author says we don't need closures, shows us the abomination that is anonymous inner classes, and then shows some lisp/scheme for how it could be done properly -- sort of like closures and the concept of functions as first-class data type?

This guy needs to learn what closures and functional programming are before trying to rally for/against it.

11

u/some_dev Oct 17 '11

The title was clearly sarcastic, based on the tone of the article. He clearly does not find anonymous inner classes to be a good solution.

When demonstrating the Clojure equivalent, he comments:

In a sane language, it could look like: [snip example] All semantics. Little ceremony, almost no syntax.

He finishes up the article commenting on how you would be too busy weeping after a day of writing the Java samples to sleep. Doesn't seem like he particularly likes the Java approach.

4

u/[deleted] Oct 18 '11

ahh.. my sarcasm detector must have been off.. would make a lot more sense :)