Slide 1

Slide 1 text

Simplify migrating to Kotlin How the right architecture can Nico Krijnen

Slide 2

Slide 2 text

Nico Krijnen @nicokrijnen nkrijnen nicokrijnen

Slide 3

Slide 3 text

Why migrate to Kotlin?

Slide 4

Slide 4 text

Why migrate to Kotlin? NullPointerException
 70% of Production Environments #1 Source: overops.com

Slide 5

Slide 5 text

Why migrate to Kotlin?

Slide 6

Slide 6 text

Why migrate to Kotlin? https://youtu.be/2yXtZ8x7TXw?t=569 Shared mutable data needs synchronisation

Slide 7

Slide 7 text

Java 2 Kotlin

Slide 8

Slide 8 text

Just press convert!

Slide 9

Slide 9 text

Just press convert!

Slide 10

Slide 10 text

Rewrite time! Rewrite time?

Slide 11

Slide 11 text

Rewrite time! Rewrite time?

Slide 12

Slide 12 text

Rewrite time! Rewrite time?

Slide 13

Slide 13 text

Rewrite time! Rewrite time?

Slide 14

Slide 14 text

Techniques Hexagonal Vertical slice Value objects Encapsulation Tests

Slide 15

Slide 15 text

Side-step Understanding Hexagonal architecture... Direction of dependency Hexagonal – Vertical Slice – Value Objects – Encapsulation – Tests

Slide 16

Slide 16 text

Direction of dependency

Slide 17

Slide 17 text

Direction of dependency

Slide 18

Slide 18 text

Controlling direction of dependency

Slide 19

Slide 19 text

Controlling direction of dependency

Slide 20

Slide 20 text

Controlling direction of dependency

Slide 21

Slide 21 text

Controlling direction of dependency

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Techniques Hexagonal architecture Hexagonal – Vertical Slice – Value Objects – Encapsulation – Tests

Slide 29

Slide 29 text

Source: github.com/Sairyss/domain-driven-hexagon

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Dependencies only point inward

Slide 32

Slide 32 text

✓ More modular ✓ Clear separation ✓ Swap implementations Architectural benefits Tradeoffs: ❌ Have to add abstractions ❌ Can be hard not to leak details in those abstractions

Slide 33

Slide 33 text

Core with no dependencies ✓ Easy to test ✓ Easy to change ✓ Easy to reason about

Slide 34

Slide 34 text

How does that help migrate to Kotlin? ✓ Isolate most important code ✓ Kotlin where it matters most ✓ Outside can remain Java ✓ Outside modules can be isolated from each other

Slide 35

Slide 35 text

How does that help migrate to Kotlin? ✓ Isolate most important code ✓ Kotlin where it matters most ✓ Outside can remain Java ✓ Outside modules can be isolated from each other

Slide 36

Slide 36 text

How to start?

Slide 37

Slide 37 text

Techniques Vertical slice architecture Hexagonal – Vertical Slice – Value Objects – Encapsulation – Tests

Slide 38

Slide 38 text

Vertical slices

Slide 39

Slide 39 text

Vertical slices

Slide 40

Slide 40 text

Vertical slices

Slide 41

Slide 41 text

Architectural benefits ✓ Clear separation ✓ Isolated & modular ✓ High cohesion ✓ Low coupling ✓ Minimise feature complexity

Slide 42

Slide 42 text

Vertical slices make it easy to ✓ Keep a feature in your head ✓ Refactor code ✓ Understand usage ✓ Prevent coupling ✓ Take small steps ✓ Limit your blast radius

Slide 43

Slide 43 text

How does that help migrate to Kotlin? ✓ Introduce Kotlin feature-by-feature ✓ Evolve architecture feature-by-feature ✓ Take small steps

Slide 44

Slide 44 text

Techniques Value objects Hexagonal – Vertical Slice – Value Objects – Encapsulation – Tests

Slide 45

Slide 45 text

Value objects

Slide 46

Slide 46 text

Value objects

Slide 47

Slide 47 text

Value objects

Slide 48

Slide 48 text

Validation

Slide 49

Slide 49 text

Value objects

Slide 50

Slide 50 text

(De)Serialization

Slide 51

Slide 51 text

How does that help migrate to Kotlin? ✓ Easy to write in Kotlin ✓ Introduce them
 one at a time ✓ Take small steps

Slide 52

Slide 52 text

Techniques Encapsulation Hexagonal – Vertical Slice – Value Objects – Encapsulation – Tests

Slide 53

Slide 53 text

Encapsulation

Slide 54

Slide 54 text

Encapsulation

Slide 55

Slide 55 text

Encapsulation

Slide 56

Slide 56 text

Encapsulation

Slide 57

Slide 57 text

Encapsulation makes it easy to ✓ Keep a feature in your head ✓ Refactor code ✓ Understand usage ✓ Freely change implementation ✓ Limit your blast radius ✓ Take small steps

Slide 58

Slide 58 text

Tests And what if you have none... Hexagonal – Vertical Slice – Value Objects – Encapsulation – Tests

Slide 59

Slide 59 text

Test suite quality Do not accept: ❌ Flakey tests ❌ Slow tests ❌ Bad test isolation ❌ Missing assertions ❌ Testing implementation details

Slide 60

Slide 60 text

How does Kotlin help with tests? Test code should: ✓ Be readable ✓ Communicate intent of module Kotlin helps here through: ✓ Expressiveness ✓ DSL capabilities Write a failing test Make the test pass Refactor

Slide 61

Slide 61 text

What about the old tests?

Slide 62

Slide 62 text

What if you have no tests? “Legacy Code is code without tests” Michael Feathers: Working Effectively with Legacy Code

Slide 63

Slide 63 text

What if you have no tests? "There is only one way to eat an elephant: a bite at a time." understandlegacycode.com “Legacy Code is code without tests” Michael Feathers: Working Effectively with Legacy Code

Slide 64

Slide 64 text

Techniques Hexagonal Vertical slice Value objects Encapsulation Tests

Slide 65

Slide 65 text

Take small steps

Slide 66

Slide 66 text

How the right architecture can Simplify migrating to Kotlin Take small steps Nico Krijnen @nicokrijnen nkrijnen nicokrijnen