Re: Refactoring to a Closure
Kim Gräsman <[email protected]>
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <[email protected]> |
Hello, I'd expect it to go the other way around: Convert Closure to Function. I've always seen lambda expressions as the most 'concrete' form of code partitioning. As I see it, you create one because you need a function pointer to pass to someone else, and the code you want to pass isn't already isolated in a function. Once it's useful to name the expression (e.g. for reuse or clarity), you can extract the code block into a named function. Of course, I rarely use closures myself, working in C++, so I could be missing something. - Kim On Fri, Dec 18, 2009 at 22:48, jcsextro <[email protected]> wrote: > Below is a blog post I have written about Java and a straw-man proposal to add closures to Java 7. I am interested in your thoughts about this. > > http://www.agileevidence.com/ > Does Java Need an 'Extract Closure' Refactoring? > > A straw-man writeup has been proposed by Mark Reinhold for including Lambda expressions (or Closures) in Java 7. > > Over the course of my career as a developer I have never used a language where closures were a tool in the developers' toolbox. Because of this my brain does not create solutions using closures. Since my conversion to Test Driven Development I work hard to ensure that I am implementing the simplest solution possible for the feature that I am developing. For this reason I have titled this post "Does Java Need an 'Extract Closure' Refactoring?" rather than something more obvious, such as "Does Java Need Closures?" > > 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. > > The only way I can envision myself using a closure would be as the result of a refactoring. For me to extract code into a closure it will have to make the code easier to read and/or improve the reusability of the code. ------------------------------------ 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/