aftermath of functional programming. the good parts
TRANSCRIPT
![Page 1: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/1.jpg)
aftermath of functional programming
the good parts
@ggalmazor @buntplanet
![Page 2: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/2.jpg)
disclaimer
![Page 3: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/3.jpg)
functional programming
![Page 4: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/4.jpg)
object orientation
![Page 5: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/5.jpg)
“FP != OO”
![Page 6: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/6.jpg)
mutation
![Page 7: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/7.jpg)
why bother
![Page 8: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/8.jpg)
equality rules
Stuff a = new Stuff();Stuff b = a.changeSomething(); if (a.equals(b)) System.out.println("WTF");
![Page 9: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/9.jpg)
output argsStuff a = new Stuff(); // a.something holds 42 doStuffWith(a); // a.something holds 33 // WTF
![Page 10: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/10.jpg)
entity != value
![Page 11: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/11.jpg)
surprisesa.setSuch();a.setWow();a.setVery();a.setCoupling();
![Page 12: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/12.jpg)
concurrency
![Page 13: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/13.jpg)
control
![Page 14: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/14.jpg)
how to avoid it
![Page 15: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/15.jpg)
change your design
![Page 16: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/16.jpg)
isolate mutation
![Page 17: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/17.jpg)
copy on write
![Page 18: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/18.jpg)
tips
![Page 19: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/19.jpg)
ValueObjectclass Stuff { private final Integer aNumber; private final String aString; Stuff(Integer aNumber, String aString) { this.aNumber = aNumber; this.aString = aString; } … }
![Page 20: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/20.jpg)
class Stuff { … @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Stuff stuff = (Stuff) o; return Objects.equals(aNumber, stuff.aNumber) && Objects.equals(aString, stuff.aString); } … }
ValueObject
![Page 21: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/21.jpg)
ValueObjectclass Stuff { …
@Override public int hashCode() { return Objects.hash(aNumber, aString); } … }
![Page 22: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/22.jpg)
factories
![Page 23: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/23.jpg)
functional data structures
![Page 24: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/24.jpg)
side effects
![Page 25: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/25.jpg)
why bother
![Page 26: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/26.jpg)
accidental complexity
![Page 27: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/27.jpg)
coupling
![Page 28: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/28.jpg)
cqrs
![Page 29: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/29.jpg)
object serialization in a distributed context
final AtomicInteger counter = new AtomicInteger(0);rdd.map(stuff -> { int i = counter(); return OtheStuff(i, stuff);});
![Page 30: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/30.jpg)
tips
![Page 31: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/31.jpg)
think in pure functions
![Page 32: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/32.jpg)
isolate and identify side effects
![Page 33: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/33.jpg)
functional data structures
![Page 34: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/34.jpg)
tools
![Page 35: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/35.jpg)
option
![Page 36: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/36.jpg)
nulls
![Page 37: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/37.jpg)
monad
![Page 38: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/38.jpg)
antipatterns
Optional.ofNullable(maybeNull).get();
![Page 39: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/39.jpg)
antipatternsOptional<Object> o = Optional.ofNullable(maybeNull); if (o.isPresent()) doStuffWith(o.get());
![Page 40: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/40.jpg)
antipatrones
Optional<List<Object>> foo
![Page 41: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/41.jpg)
antipatrones
Map<String,Optional<Object>> foo
![Page 42: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/42.jpg)
tips
![Page 43: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/43.jpg)
tuple
![Page 44: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/44.jpg)
design exploration
![Page 45: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/45.jpg)
tips
![Page 46: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/46.jpg)
try
![Page 47: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/47.jpg)
exceptions
![Page 48: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/48.jpg)
when i use try
![Page 49: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/49.jpg)
when i use try
Try.of(someComputation)
![Page 50: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/50.jpg)
Try.of(someComputation) .onFailure(logger::error) .get()
when i use try
![Page 51: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/51.jpg)
when i use tryTry.of(someComputation) .flatMap(someOtherComputation) .onFailure(logger::error) .get()
![Page 52: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/52.jpg)
when i use tryTry.run(someVoidComputation) .anThen(someVoidComputation) .onFailure(logger::error) .get()
![Page 53: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/53.jpg)
when i use tryTry.of(someComputation) .orElse(42)
![Page 54: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/54.jpg)
antipatterns
![Page 55: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/55.jpg)
antipatternsTry.run(()-> { int a = somethingOverHere(); int b = somethingOverThere(a); doTheGangnamStyle(a,b); }).onFailure(t-> { logger.error(“Everything’s f*cked!!!”, t); }).get();
![Page 56: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/56.jpg)
antipatternsTry.of(thisWillReturnNull).toOption()
![Page 57: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/57.jpg)
antipatronesTry.of(someVoidComputation) .map(thisWillGetDirty)
![Page 58: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/58.jpg)
functional data structures
![Page 59: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/59.jpg)
why bother
![Page 60: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/60.jpg)
know your tools
![Page 61: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/61.jpg)
filter, map, fold
![Page 62: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/62.jpg)
impact in your design
![Page 63: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/63.jpg)
tips
![Page 64: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/64.jpg)
small blocks
![Page 65: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/65.jpg)
don’t go crazy
![Page 66: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/66.jpg)
really. don’t go crazy
![Page 67: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/67.jpg)
types
![Page 68: Aftermath of functional programming. The good parts](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2f9151a28abf9718b4595/html5/thumbnails/68.jpg)
thanks!