My talk about how the Clean Code principles and techniques apply/change when you start using functional programming with Java 8. Presented in Paris at Devoxx FR 2018
Clean Code with Java 8 - Functional Patterns and Best Practices
1. #DevoxxFR @victorrentea
Clean Code with Java 8
Functional Patterns and Best Practices
- live coding marathon -
Victor Rentea
VictorRentea@gmail.com
www.VictorRentea.ro
1
2.
3. Victor Rentea
13 years of Java
Lead Architect at IBM
Tech Team Lead and Consultant
Clean Code Evangelist
VictorRentea@gmail.com www.VictorRentea.ro
Krakow Vienna Sofia Casablanca Bucharest Iasi Belgrade Kiew Paris Moscow Barcelona
12. #DevoxxFR @victorrentea
Descriptive Names
Best Lambdas are fit, thin one-liners
Extract heavy lambdas into named ::methods
in the same class
in the item class
as static methods
-> {a-nonymous functions
12
Lambdas
13. #DevoxxFR @victorrentea
Stream Wrecks
1 usecase = 1 single chain of 30 function calls.
Don't do that !
We beg you !
We have children, families,…
Break them using explanatory variables
Small
Methods
Five Lines
13
18. #DevoxxFR @victorrentea
Avoid Checked Exceptions
java.util.function interfaces don't declare any throws
Which is good !
You shall suffer if you work with non-Runtime Exceptions!
But if you insist:
- Define throwing functional interfaces
- Use libraries: jool, vavr...
18
19. #DevoxxFR @victorrentea
Type-specific Logic
switch
Switch Hunt Day®
Hope to find them all: JDD
Simplest to Read
1 switch = 1 method
case XX: return …
OOP
Extends is BAD
ONE Shot
Children90Movie
enum
Isolated Logic
In enum methods
Logic with Dependencies
Function references on enums
(bean passed as param)
19