Slide 1

Slide 1 text

"Bring Your Kotlin To Work" Day September 2017 Maybe

Slide 2

Slide 2 text

Guillermo Orellana Senior Keyboard Smasher github.com/wiyarmir https://www.linkedin.com/in/guillermoorellana @wiyarmir

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

– bringyourdogtoworkday.co.uk “[…] the presence of pets can substantially reduce a person’s stress level in the workplace. Increased job satisfaction, team co-operation and morale have all been reported in employees that spend the workday with their pets”

Slide 5

Slide 5 text

– me “[…] the presence of Kotlin can substantially reduce a person’s stress level in the workplace. Increased job satisfaction, team co-operation and morale have all been reported in employees that spend the workday with Kotlin”

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

The case for Kotlin

Slide 11

Slide 11 text

Don’t stay in your Java bubble

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Learn the basics

Slide 14

Slide 14 text

val var

Slide 15

Slide 15 text

Type Type?

Slide 16

Slide 16 text

@NonNull private final String name = "Java"; private val name: String = "Kotlin"

Slide 17

Slide 17 text

It's OK to write Java-ish Kotlin

Slide 18

Slide 18 text

Improve by doing

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Let the IDE help you

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Let other people help you

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Let the Kotlin community help you

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Kotlin won't make bad code good

Slide 29

Slide 29 text

The case against Kotlin

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Fighting the compiler

Slide 32

Slide 32 text

@JvmField @JvmStatic @JvmName @JvmSuppressWildcards @JvmWildcard @JvmOverloads

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Final by default

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Style guide

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

¯\_(ツ)_/¯

Slide 44

Slide 44 text

Quizz time!

Slide 45

Slide 45 text

class MarketDataViewModel { init { compositeDisposable.add(bindToMarketData()) } val compositeDisposable = CompositeDisposable() fun bindToMarketData(): Disposable = TODO() }

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

class MarketDataViewModel { val compositeDisposable = CompositeDisposable() init { compositeDisposable.add(bindToMarketData()) } fun bindToMarketData(): Disposable = TODO() }

Slide 48

Slide 48 text

class MarketDataViewModel { val compositeDisposable = CompositeDisposable() init { compositeDisposable.add(bindToMarketData()) } val mapper = TODO() fun bindToMarketData(): Disposable = retrieveMarketData.getStream() .map(mapper) .subscribe() }

Slide 49

Slide 49 text

RuntimeException

Slide 50

Slide 50 text

class MarketDataViewModel { val compositeDisposable = CompositeDisposable() init { compositeDisposable.add(bindToMarketData()) } val mapper = TODO() fun bindToMarketData(): Disposable = retrieveMarketData.getStream() .map(mapper) .subscribe() }

Slide 51

Slide 51 text

class MarketDataViewModel { val compositeDisposable = CompositeDisposable() init { compositeDisposable.add(bindToMarketData()) } val mapper = TODO() fun bindToMarketData(): Disposable = retrieveMarketData.getStream() .map(mapper) .subscribe() }

Slide 52

Slide 52 text

class MarketDataViewModel { val compositeDisposable = CompositeDisposable() init { compositeDisposable.add(bindToMarketData()) } val mapper = TODO() fun bindToMarketData(): Disposable = retrieveMarketData.getStream() .map(mapper) .subscribe() }

Slide 53

Slide 53 text

class MarketDataViewModel { val compositeDisposable = CompositeDisposable() init { compositeDisposable.add(bindToMarketData()) } val mapper = TODO() fun bindToMarketData(): Disposable = retrieveMarketData.getStream() .map(mapper) .subscribe() }

Slide 54

Slide 54 text

class MarketDataViewModel { val compositeDisposable = CompositeDisposable() init { compositeDisposable.add(bindToMarketData()) } val mapper = TODO() fun bindToMarketData(): Disposable = retrieveMarketData.getStream() .map(mapper) .subscribe() }

Slide 55

Slide 55 text

RuntimeException

Slide 56

Slide 56 text

class MarketDataViewModel { val compositeDisposable = CompositeDisposable() val mapper = TODO() init { compositeDisposable.add(bindToMarketData()) } fun bindToMarketData(): Disposable = retrieveMarketData.getStream() .map(mapper) .subscribe() }

Slide 57

Slide 57 text

What I like from Kotlin

Slide 58

Slide 58 text

Data Classes

Slide 59

Slide 59 text

"POJOs"

Slide 60

Slide 60 text

public class Balance { @NonNull private final BalanceType type; private final int value; public Balance(@NonNull BalanceType type, int value) { this.type = type; this.value = value; } @NonNull public BalanceType getType() { return type; } public int getValue() { return value;

Slide 61

Slide 61 text

return type == balance.type; } @Override public int hashCode() { int result = type.hashCode(); result = 31 * result + value; return result; } @Override public String toString() { return "Balance{" + "type=" + type + ", value=" + value + '}'; } }

Slide 62

Slide 62 text

data class Balance (val type: BalanceType, val value: Int)

Slide 63

Slide 63 text

data class Balance ( val type: BalanceType = Invalid, val value: Int = 0 )

Slide 64

Slide 64 text

Named parameters

Slide 65

Slide 65 text

fun fromEntity(e: ModerationEntity) = ModerationModel( header = e.header, body = e.message, ctaPrimary = e.ctaPrimary, ctaSecondary = e.ctaSecondary, photos = e.photos )

Slide 66

Slide 66 text

Sealed classes

Slide 67

Slide 67 text

sealed class BalanceResult { data class Balance( val type: BalanceKind = Invalid, val value: Int = 0 ): BalanceResult() object BalanceError: BalanceResult() }

Slide 68

Slide 68 text

Bonus points

Slide 69

Slide 69 text

class MarketDataRepository( private val store: ReactiveStore, private val marketDataService: MarketDataService, private val marketDataMapper: MarketDataMapper) { fun getAllMarketData(): Flowable>> = store.getAll() fun fetchMarketData(): Completable = marketDataService.getMarketPrice() .subscribeOn(Schedulers.io()) .observeOn(Schedulers.computation()) .map(marketDataMapper) .doOnSuccess({ store.replaceAll(it) }) .toCompletable() } }

Slide 70

Slide 70 text

Looks great in slides

Slide 71

Slide 71 text

Fits great in slides

Slide 72

Slide 72 text

Kotlin is here to stay

Slide 73

Slide 73 text

Kotlin is here to stay

Slide 74

Slide 74 text

Thank you!

Slide 75

Slide 75 text

Inspiration • The Case Against Kotlin - Pinterest Engineering • Kotlin for grumpy Java developers - Pinterest Engineering • Kotlin: The Good, The Bad, and The Ugly

Slide 76

Slide 76 text

Links • Try Kotlin - https://try.kotlinlang.org/ • Kotlin Koans - https://try.kotlinlang.org/#/Kotlin%20Koans/ • Kategory - https://github.com/kategory/kategory/ • Kotlinlang Slack - slack.kotlinlang.org

Slide 77

Slide 77 text

Image credits • Android Studio Logo - Android Open Source Project (CCBY) • Renibeni - C. Mclean (Free Domain) • John Charles Dollman - Table d'Hote at a Dogs' Home (Free Domain) • Forbidden - Wikimedia (Free Domain) • 869018 - Pixbay (Free Domain)

Slide 78

Slide 78 text

Questions? github.com/badoo https://habrahabr.ru/company/badoo/ @BadooDev