0% found this document useful (0 votes)
88 views20 pages

Clean Code With Java 8: Functional Patterns and Best Practices - Live Coding Marathon

Uploaded by

Monika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views20 pages

Clean Code With Java 8: Functional Patterns and Best Practices - Live Coding Marathon

Uploaded by

Monika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Clean Code with Java 8

Functional Patterns and Best Practices

- live coding marathon -

Victor Rentea
[email protected]
www.VictorRentea.ro

#DevoxxFR @victorrentea 1
Victor Rentea
13 years of Java

Lead Architect at IBM


Tech Team Lead and Consultant

Clean Code Evangelist


Krakow Vienna Sofia Casablanca Bucharest Iasi Belgrade Kiew Paris Moscow Barcelona

[email protected] www.VictorRentea.ro
since 2013
Independent
1500+ hours
Technical Trainer 1000+ developers

 Spring
 Hibernate
 Clean Code, Architectures
 Java 8, Design Patterns
 Unit Testing
 Java Performance
tough clients:  Scala & more...

#DevoxxFR @victorrentea [email protected] VictorRentea.ro


Not Convinced?

#DevoxxFR @victorrentea 5
Not Convinced?

They were!
Hard-Core Mode

#DevoxxFR @victorrentea
Hard-Core Mode

#DevoxxFR @victorrentea
Let's CODE !!
I'll push everything here:
https://github.com/victorrentea/clean-code-java8-devoxxfr

#DevoxxFR @victorrentea 9
#DevoxxFR @victorrentea
The Clean Code Rules

Applied to Java 8

#DevoxxFR @victorrentea 11
Descriptive Names

a-nonymous functions
BestLambdas
Lambdas are fit, thin one-liners
-> {
Extract heavy lambdas into named ::methods

 in the same class

 in the item class

 as static methods

#DevoxxFR @victorrentea 12
Stream Wrecks
1 usecase = 1 single chain of 30 function calls.

Small Don't do that !


We beg you !
Methods
Five Lines We have children, families,…

Break them using explanatory variables

#DevoxxFR @victorrentea 13
Optional
No Nullable Parameters
Instead: thatOpt.map(myFunction)

Avoid Returning Null, Throw Ex


… or return an Optional

PS: don't be afraid of Orcs, Monads, or .flatMap


#DevoxxFR @victorrentea 14
Passing-a-Block

Pass logic to your function

The Funeral of Template Method™

#DevoxxFR @victorrentea 15
Loan Pattern
You work with a resource
that is managed for you

Decouples real logic from infra code

#DevoxxFR @victorrentea 16
Execute Around Pattern

Explicit AOP

~ Proxy™ or Decorator™

#DevoxxFR @victorrentea 17
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...


#DevoxxFR @victorrentea 18
Type-specific Logic
switch OOP enum
Switch Hunt Day ® Isolated Logic
Extends is BAD
Hope to find them all: JDD In enum methods

Simplest to Read ONE Shot Logic with Dependencies


1 switch = 1 method Children90Movie Function references on enums
case XX: return … (bean passed as param)

#DevoxxFR @victorrentea 19
Merci
Let's Chat:
@victorrentea
[email protected]
Disclaimer: The use of ® or
™ is the slides is only www.VictorRentea.ro
anecdotic.
#DevoxxFR @victorrentea 20

You might also like