Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Functional Patterns with Java8 @Bucharest Java User Group

42,532 views

Published on

The slides for the presentation I gave at Bucharest Java User Group. This session was the largest Romanian Java community meetup ever organized until now.

Published in: Software
  • Login to see the comments

  • Be the first to like this

Functional Patterns with Java8 @Bucharest Java User Group

  1. 1. #DevoxxUK @victorrentea Functional Programming Patterns with Java 8 - live coding marathon - Victor Rentea IBM Lead Architect & Independent Trainer victor.rentea@gmail.com www.VictorRentea.ro All the commits will be pushed to https://github.com/victorrentea/functional-patterns-bjug-2018.git
  2. 2. 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 London Krakow Vienna Sofia Casablanca Bucharest Belgrade Kiew Barcelona
  3. 3. victorrentea.ro @victorrentea  Spring  Hibernate  Clean Code, Architectures  Java 8, Design Patterns  Unit Testing  Java Performance  Scala & more... Independent Technical Trainer & Coach Victor.rentea@gmail.com VictorRentea.ro 1000+ devs 5 years tough clients:
  4. 4. victorrentea.ro @victorrentea Not Convinced? 5
  5. 5. Not Convinced? They were!
  6. 6. victorrentea.ro @victorrentea Hard-Core Switch
  7. 7. victorrentea.ro @victorrentea Hard-Core Switch
  8. 8. victorrentea.ro @victorrentea Let's CODE !! 9 I'll push everything here: https://github.com/victorrentea/functional-patterns-devoxx-uk
  9. 9. victorrentea.ro @victorrentea
  10. 10. victorrentea.ro @victorrentea The Clean Code Rules Applied to Java 8 11
  11. 11. victorrentea.ro @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
  12. 12. victorrentea.ro @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
  13. 13. victorrentea.ro @victorrentea Optional Instead: thatOpt.map(myFunction) No NullableParameters Avoid Returning Null,Throw Ex … or return an Optional PS: don't be afraid of Orcs, Monads, or .flatMap 14
  14. 14. victorrentea.ro @victorrentea Passing-a-Block Pass logic to your function The Funeral of Template Method™ 15
  15. 15. victorrentea.ro @victorrentea Loan Pattern You work with a resource that is managed for you Decouples real logic from infra code 16
  16. 16. victorrentea.ro @victorrentea Execute Around Pattern Explicit AOP ~ Proxy™ or Decorator™ 17
  17. 17. victorrentea.ro @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... 18
  18. 18. victorrentea.ro @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
  19. 19. victorrentea.ro @victorrentea Thank You! 20 Disclaimer: The use of ® or ™ is the slides is only anecdotic. So good we can ask more explanations after the Pizza What was that??
  20. 20. victorrentea.ro @victorrentea Thank You! 21 Disclaimer: The use of ® or ™ is the slides is only anecdotic. victor.rentea@gmail.com www.VictorRentea.ro Let's Chat:
  21. 21. victorrentea.ro @victorrentea Thank You! 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 In-house/remote training or coaching? What do You want us to do the second hour? (after the Pizza) victorrentea.ro/vote.html Dissect some examples Basic Java8 Tutorial (Slow-motion) Mocking Kata TDD Kata Spring @Transactional victor.rentea@gmail.com www.VictorRentea.ro

×