The backing slides for my live coding session at Devoxx UK London 2018. Summarizing all the conclusions. A summary of how to apply clean code principles in Java8 code.
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
Functional Patterns with Java8 at Devoxx UK - Slides
1. @victorrentea
Functional Programming Patterns with Java 8
Victor Rentea
IBM Architect & Independent Trainer
victorrentea.ro
All the commits will be pushed to
https://github.com/victorrentea/functional-patterns-devoxx-uk
2.
3. Victor Rentea
13 years of Java
Lead Architect at IBM
Tech Team Lead and Consultant
Clean Code Evangelist
victor.rentea@gmail.com www.VictorRentea.ro
Moscow Paris Krakow Vienna Sofia Casablanca Bucharest Iasi Belgrade Kiew Barcelona
12. #DevoxxUK @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
13
Lambdas
13. #DevoxxUK @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
14
18. #DevoxxUK @victorrentea
Avoid Checked Exceptions
java.util.function interfaces don't declare any throws
Which is good !
You must suffer if you work with non-Runtime Exceptions!
But if you insist:
- Define throwing functional interfaces
- Use libraries: jool, vavr...
19
19. #DevoxxUK @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)
20
22. #DevoxxUK @victorrentea
Thank You!
23
I'm available
a statement of seniority
I use both
hemispheres
Tough meetings?
Abused estimates?
Purpose of code:
1. Maintainable
-- Uncle Bob
Functional Party
Activist
Stay into
The Light
I brought you some
Motivational Stickers
@victorrentea
victor.rentea@gmail.com
www.VictorRentea.rocome and grab
yours
If you really-really liked it:
http://victorrentea.ro#recommend
In-house /remote
training or coaching?