Re: Refactoring to a Closure

Adam Sroka <[email protected]>
Newsgroups gmane.comp.programming.refactoring
Message-ID <[email protected]>
On Sat, Dec 19, 2009 at 3:36 AM, Mirko Stocker <[email protected]> wrote:
>
>
>
> Hi!
>
> On Friday 18 December 2009 22:48:42 jcsextro wrote:
> > I won't write any code using closures because a closure isn't the simplest
> > thing that can work. I know this because of the millions of bits of code
> > that I have already written in Java without closures.
>
> But, if closures weren't even available in the languages you used, no wonder
> you haven't had the chance to use them :-) How many times have you used an
> anonymous class in Java? I'd bet that in most cases, passing a simple closure
> would have done the job as well, and with much less code to write.
>

+1

More to the point. Of all those millions of problems you've solved in
Java, how many of them involved iterating over a collection in some
kind of loop in order to get some information from the collection and
make some decision? Ruby uses anonymous iterator functions to do this.
It is a much simpler solution with a cleaner, less procedural syntax.
Some forms of this (the ones that remember the state of some variable
inside the iterator, e.g. collect or filter) are using closures. Most
of the folks who think Java needs closures are after this feature.

> I'd recommend to take a look at Scala to see how Java with closures could look
> like.
>

Or JRuby, or Groovy, or Clojure, etc (I think there are now more JVM
languages that support them than not.) You could even look at the way
they are used in JavaScript libraries like Prototype.


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/refactoring/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/refactoring/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.