• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Functional Programming in Java -- second edition?

 
Ranch Hand
Posts: 885
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Venkat,
I noticed that this is the Second Edition of the book and both Amazon and the Pragmatic Programmer's website say "Updated to the latest version of Java, this edition has four new chapters on error handling, refactoring to functional style, transforming data, and idioms of functional programming."  Without posting large chunks of the chapter, could you give me a feel for how to go about "refactoring to a functional style"?   I think part of my problem is the idea that refactoring means not changing the code's behavior, how can you refactor code that has side-effect to a functional style?

Hoping this makes sense,
Burk
 
Author
Posts: 136
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Burk,

Refactoring is about changing how the code does its work without changing what it does, that is without changing its external behavior. In that sense, we have to be able to define the boundary of what we consider internal vs. external.

For example, if we consider an imperative style code where we have a local variable within the function that is mutated within a loop. As far as the loop, it has a side effect on what's outside of the loop. If that variable were a field instead of local variable, that side-effects is much worse.

In the refactoring chapter the examples discussed deal with the first case, where the changes are local. I do not focus on the larger side-effect of fields. Such side-effects will require further refactoring to remove the side-effects to fields before applying the functional techniques.
 
Burk Hufnagel
Ranch Hand
Posts: 885
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Venkat,
Ah. OK, that makes more sense. It's always nice to have an expert around to answer questions.

Thanks,
Burk
 
You don't like waffles? Well, do you like this tiny ad?
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic