Slide 1

Slide 1 text

Using Kotlin in Production @emmaguy

Slide 2

Slide 2 text

How did we get there? Did it go well? Lessons learnt

Slide 3

Slide 3 text

Convince your team

Slide 4

Slide 4 text

Have an offsite Nerd out!

Slide 5

Slide 5 text

Convince your manager(s)

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Christina Lee @ Google I/O https://www.youtube.com/watch?v=fPzxfeDJDzY

Slide 8

Slide 8 text

Everyone is sold! Let’s go!

Slide 9

Slide 9 text

“Let’s just start using it” - me, March 2017

Slide 10

Slide 10 text

Plan

Slide 11

Slide 11 text

Decide how to use it

Slide 12

Slide 12 text

Only tests? A layer of your application’s architecture? ‘Anything new’?

Slide 13

Slide 13 text

Tests only

Slide 14

Slide 14 text

@Test public void register_noPhoneNumber_showContactSupport() { when(pinManager.fetchPhoneNumber()).thenReturn(""); presenter.register(view); verify(view).showContactSupport(); }

Slide 15

Slide 15 text

@Test fun register_noPhoneNumber_showContactSupport() { whenever(pinManager.fetchPhoneNumber()).thenReturn("") presenter.register(view) verify(view).showContactSupport() }

Slide 16

Slide 16 text

Figure out any potential “incompatibilities” e.g. Realm, Lombok

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Learn & Adapt

Slide 20

Slide 20 text

Progressed to use in data layer of our app ...then in Activities (replacing ButterKnife) ...then anything new!

Slide 21

Slide 21 text

Expect discussions about nullability

Slide 22

Slide 22 text

#kotlin-tips

Slide 23

Slide 23 text

Stick with what you committed to for a while Assess Make changes

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Awesome things

Slide 26

Slide 26 text

Kotlin = great for hiring

Slide 27

Slide 27 text

@Deprecated https://hackernoon.com/how-kotlins-deprecated-relieves-pain-of-colossal-refactoring-8577545aaed

Slide 28

Slide 28 text

Extension methods

Slide 29

Slide 29 text

@Override public void showLoading() { progressBar.setVisibility(View.VISIBLE); } or override fun showLoading() { progressBar.visible() }

Slide 30

Slide 30 text

fun ImageView.loadUrl(url: String) { Picasso.with(context).load(url).into(this) } imageView.loadUrl(url)

Slide 31

Slide 31 text

fun Activity.screenWidth(): Int { val metrics = DisplayMetrics() windowManager.defaultDisplay.getMetrics(metrics) return metrics.widthPixels }

Slide 32

Slide 32 text

Named/default arguments

Slide 33

Slide 33 text

fun card( id: String = UUID.randomUUID().toString(), expires: String = "24/20", cardStatus: CardStatus = CardStatus.ACTIVE ): Card { return Card(id, expires, cardStatus) } Card(expires = "03/16", cardStatus = CardStatus.INACTIVE)

Slide 34

Slide 34 text

setUpgradeBannerStyle(true) or setUpgradeBannerStyle(loudStyle = true)

Slide 35

Slide 35 text

apply { }

Slide 36

Slide 36 text

val arguments = Bundle().apply { putString(KEY_ID, id) }

Slide 37

Slide 37 text

Things we learnt

Slide 38

Slide 38 text

“Convert any file you touch” doesn’t work

Slide 39

Slide 39 text

There is no ‘static’

Slide 40

Slide 40 text

companion object {} https://medium.com/@BladeCoder/exploring-kotlins-hidden-costs-part-1-fbb9935d9b62

Slide 41

Slide 41 text

Where do I put constants?

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Auto convert is not always your friend

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

SAM Conversion

Slide 46

Slide 46 text

public interface PayeeClickListener { void onPayeeClicked(Payee payee); }

Slide 47

Slide 47 text

adapter.setPayeeClickListener(payee -> /* do something */);

Slide 48

Slide 48 text

adapter.setPayeeClickListener(PayeeClickListener { /* do something */ })

Slide 49

Slide 49 text

But, if we convert the interface to Kotlin

Slide 50

Slide 50 text

adapter.setPayeeClickListener(object : PayeeClickListener { override fun onPayeeClicked(payee: Payee) { // do something } })

Slide 51

Slide 51 text

New thing = less mature ecosystem IDE integration, style guide, code coverage tools

Slide 52

Slide 52 text

Would you do it again?

Slide 53

Slide 53 text

Absolutely.

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Thank you! @emmaguy

Slide 56

Slide 56 text

Questions? @emmaguy