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.

Kpi driven-java-development

14 views

Published on

Kpi driven-java-development

Published in: Internet
  • Be the first to comment

  • Be the first to like this

Kpi driven-java-development

  1. 1. KPI driven JAVA(functional) development Gradual journey from imperative to functional development in JAVA Anirban Bhattacharjee – Architect @ Walmart Labs
  2. 2. About my functional exposure Writing java for living … since JDK 4 (mostly OO way in the last decade) Came across clojure/scala around 2010…and used in production Learning and using F# since last year @work Occasional tinkering with OCaml and Haskell
  3. 3. Problem Statement • We have tons of code written in JAVA • Where will I find developer? • One company one tech stack… • Performance, Monitoring, Support? • Interop, library support. CAN I STILL WRITE FUNCTIONAL CODE, IMPROVE KPI, MAKE MY LEADERSHIP HAPPY
  4. 4. Today’s JAVA OOO -> FP Functional programming is mainstream since JDK 8 (GA – 2014) We could use the power of FP ever since then Powerful Lambdas/Streams Collection Enhancements Function, Supplier, Consumer
  5. 5. Growing eco-system • Many promising and production ready libraries • Clean APIs • Reduction of verbosity, testable and concise code • Great dev tools • Rapid learning from other functional programming languages
  6. 6. KPI improvements (target areas) using FP in java SONAR DEVELOPER PRODUCTIVITY Time to market GC, PERF IMPROVEMENT
  7. 7. Journey to FP • Birds eye view of functional java • Additional powerful frameworks  vavr  functional java  streamex  Atlassian fugue  misc…
  8. 8. Functional Java : Stream basics Loop List<String> countries = new ArrayList<>(); for (String s : allCountries) { if (s.startsWith(“I")) { countries.add(s); } } Stream List<String> countries = allCountries.stream() .filter(a -> a.startsWith(“I")) .collect(toList())
  9. 9. Functional Java : Stream illustrated Origin EndOp 1 Op 2 Op n Data Pipeline Start Data Pipeline End Intermediate Operations
  10. 10. Functional Java : Map, reduce, collect List<String> list = Stream.of("India", "Iceland",“Peru“,"Italy") .filter(s -> s.startsWith("I")) .map(String::toUpperCase) .sorted() .collect(toList()) India Iceland ItalyPeru India Iceland Italy INDIA ICELAND ITALY ICELAND INDIA ITALY ICELAND INDIA ITALY 1 2 3 4 5 1 2 3 4 5
  11. 11. Intermediate Operation : Filter Ind It UKJP Ind It 1 2 Stream<String> startsWithI = Stream.of("Ind", "It", "JP", "UK") .filter(s -> s.startsWith("I")); 1 2
  12. 12. Functional Java : Intermediate Operation Ind It UKJP Ind It 1 2 Stream<String> startsWithI = Stream.of("Ind", "It", "JP", "UK") .limit(3); 1 2 JP
  13. 13. Functional Java : Intermediate Operation Ind It UKJP Ind It 1 2 Stream<String> startsWithI = Stream.of("Ind", "It", "JP", "UK", "UK") .distinct(); 1 2 JP UK UK
  14. 14. Functional Java : Intermediate Operation Ind It UKUS Ind It 1 2 Stream<String> startsWithI = Stream.of("Ind", "It", “US", "UK") .sorted(); 1 2 UK US
  15. 15. Functional Java : Intermediate Operation Ind It UKUS Ind It 1 2 Stream<String> startsWithI = Stream.of("Ind", "It", “US", "UK") .sorted(Comparator.comparing(String::length)); 1 2 UK US
  16. 16. Functional Java : Terminal Operation Ind It UKJP Ind It 1 2 Stream<String> startsWithI = Stream.of("Ind", "It", "JP", "UK") .forEach(System.out.println()); 1 2 JP UK
  17. 17. Functional Java : Downstream Collectors Ind It UKJP Ind It 1 2 Stream<String> startsWithI = Stream.of("Ind", "It", "JP", "UK”, "UK” ) .collect(Collectors.toSet()); 1 2 JP UK UK
  18. 18. Functional Java : Custom Downstream collector return Collector.of( () -> new ArrayList<T>(), // supplier (a, e) -> { a.add(e); }, // accumulator (a, b) -> { a.addAll(b); return a; }, // combiner a -> { // finisher a.sort(comp); DA da = downstream.supplier().get(); for (T e : a) downstream.accumulator().accept(da, e); return downstream.finisher().apply(da); }); Stream<Locale> locales = Stream.of(Locale.getAvailableLocales()); var result = locales.collect( groupingBy(Locale::getCountry, mapping(Locale::getDisplayName, sorting(String::compareTo, joining(",")))));
  19. 19. Functional Java : Collection enhancemetns map.forEach((k, v) -> System.out.println(k + v));for (Map.Entry<String,String> entry : map.entrySet()) System.out.println(entry.getKey() + entry.getValue()); for (Map.Entry<String,String> entry : map.entrySet()) entry.setValue(entry.getValue().toLowerCase()); map.replaceAll((k, v) -> v.toLowerCase()); map.computeIfAbsent(str, x -> HashsSet::new).add(i);Set<Integer> set = multimap.get(str); if (set == null) { set = new HashSet<>(); multimap.put(str, set); } set.add(i);
  20. 20. Functional Java : More Collection Examples Contents
  21. 21. Functional Java : Consumer, Supplier, Functions Contents
  22. 22. Functional Java : Byte Code • Is Functional java only syntactic sugar? • Byte code improvements • Example of Byte code of BEFORE and AFTER
  23. 23. Functional Java : Byte Code • Is Functional java only syntactic sugar? • Byte code improvements • Example of Byte code
  24. 24. Vavr
  25. 25. Vavr : basics • New functional data-structures (persistent) with superior performance • Pure Functions, monads, superior exception management • Less verbosity • Great Functional semantics
  26. 26. Vavr : Examples • LIST, TREE, SET and the cool APIs •
  27. 27. Vavr : Examples • CHECKED FUNCTION, CONSUMER, PREDICATE •
  28. 28. Vavr : Examples • CHECKED FUNCTION, CONSUMER, PREDICATE •
  29. 29. Other frameworks: Streamex, Fugue etc.. • CHECKED FUNCTION, CONSUMER, PREDICATE •
  30. 30. Million Dollar Question: KPI improvement • SONAR (detailed examples)
  31. 31. Million Dollar Question: KPI improvement • Developer Productivity -REPL • Developer Productivity - IDE support
  32. 32. Million Dollar Question: KPI improvement • All about GC
  33. 33. Million Dollar Question: KPI improvement • Ease of testing and performance

×