Chapter 7. Testing, Debugging, and Refactoring
The rising popularity of techniques such as refactoring, test-driven development (TDD), and continuous integration (CI) mean that if weâre going to use lambda expressions in our day-to-day programming, we need to understand how to test code using them and written with them.
A wealth of material has been written on how to test and debug computer programs, and this chapter isnât going to revisit all that material. If youâre interested in learning how to do TDD properly, I highly recommend the books Test-Driven Development by Kent Beck and Growing Object-Oriented Software, Guided by Tests by Steve Freeman and Nat Pryce (both from Addison-Wesley).
I am going to cover techniques specific to using lambda expressions in your code, and when you might not want to (directly) use lambda expressions at all. Iâll also talk about some appropriate techniques for debugging programs that heavily use lambda expressions and streams.
Weâre first going to look at some examples of how to refactor an existing
code base into using lambda expressions. Iâve talked a bit already about how to
do local refactoring operations, such as replacing a for
loop with a stream
operation. Here weâll take a more in-depth look at how non-collection code
can be improved.
Lambda Refactoring Candidates
The process of refactoring code to take advantage of lambdas has been given the snazzy name point lambdafication (pronounced lambda-fi-cation, practitioners of this ...
Get Java 8 Lambdas now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.