Next Level DSLs Configure your app the Kotlin way! Aaron Sarazan - - PowerPoint PPT Presentation

next level dsls
SMART_READER_LITE
LIVE PREVIEW

Next Level DSLs Configure your app the Kotlin way! Aaron Sarazan - - PowerPoint PPT Presentation

Next Level DSLs Configure your app the Kotlin way! Aaron Sarazan CTO - Stencil Ltd. https://gitlab.com/asarazan/kotlinconf18 aaron@stencil.ltd Isolated Feature Development A Plugin Its like an app, just smaller Android Manifest Plugin


slide-1
SLIDE 1

https://gitlab.com/asarazan/kotlinconf18

Next Level DSLs

Configure your app the Kotlin way!

Aaron Sarazan CTO - Stencil Ltd. aaron@stencil.ltd

slide-2
SLIDE 2
slide-3
SLIDE 3
slide-4
SLIDE 4

Isolated Feature Development

slide-5
SLIDE 5

A Plugin

It’s like an app, just smaller

slide-6
SLIDE 6

Android Manifest

slide-7
SLIDE 7

Plugin DSL

slide-8
SLIDE 8

Plugin DSL

slide-9
SLIDE 9

Plugin DSL

slide-10
SLIDE 10

Plugin DSL

slide-11
SLIDE 11

Plugin DSL

slide-12
SLIDE 12

Back to Basics

slide-13
SLIDE 13

Help! What’s a DSL?

slide-14
SLIDE 14

When you really wish your language could do the thing.

slide-15
SLIDE 15

Help! What’s a DSL?

Java

slide-16
SLIDE 16

Help! What’s a DSL?

LISP

slide-17
SLIDE 17

Help! What’s a DSL?

Ruby

slide-18
SLIDE 18

Podfiles

slide-19
SLIDE 19

Help! What’s a DSL?

Domain Specific Language

slide-20
SLIDE 20

white space

slide-21
SLIDE 21

Remove Boilerplate

slide-22
SLIDE 22

Help! What’s a DSL?

Domain Specific Language

slide-23
SLIDE 23
slide-24
SLIDE 24

Help! What’s a DSL?

Domain Specific Language

slide-25
SLIDE 25

Help! What’s a DSL?

Domain Specific Language

slide-26
SLIDE 26

Help! What’s a DSL?

Domain Specific Language

slide-27
SLIDE 27

You don’t DO the thing. You STATE the thing.

slide-28
SLIDE 28

GRADLE!

slide-29
SLIDE 29

Here’s How It Works

slide-30
SLIDE 30

Here’s How It Works

slide-31
SLIDE 31

Here’s How It Works

slide-32
SLIDE 32

Experience Get!

slide-33
SLIDE 33

Why Kotlin?

slide-34
SLIDE 34

Groovy-Style

Type-Safe Builders

slide-35
SLIDE 35

It was literally built for it.

Kotlin is made for DSLs

slide-36
SLIDE 36

When Should I Make a DSL?

slide-37
SLIDE 37

Anko

slide-38
SLIDE 38

Anko

slide-39
SLIDE 39
slide-40
SLIDE 40

Anko

slide-41
SLIDE 41

This is Really Unpleasant

...and there has to be a better way.

  • XML
  • Configuration
  • Declaration
  • Boilerplate
  • Builders
slide-42
SLIDE 42

Builders

ALWAYS a candidate for DSLs

slide-43
SLIDE 43

Readability

slide-44
SLIDE 44

Work Backwards

Start from the result that you want to enable ...then write the code that enables it!

slide-45
SLIDE 45

Start With Builders

Immutability with a side of Java-friendliness!

slide-46
SLIDE 46

@DslMarker

Prevent Scoping Mishaps!

slide-47
SLIDE 47

Good Hygiene

  • Don’t pollute the global namespace
  • Unary “+” only if well-scoped
  • Keep Lambda files next to your builder classes

○ Plugin.kt ○ PluginLambdas.kt

  • Don’t extend system types

○ String, Int, etc.

slide-48
SLIDE 48

Good Hygiene

  • Don’t pollute the global namespace
  • Unary “+” only if well-scoped
  • Keep Lambda files next to your builder classes

○ Plugin.kt ○ PluginLambdas.kt

  • Don’t extend system types

○ String, Int, etc.

  • Have fun!
slide-49
SLIDE 49

So Who’s Ready?

slide-50
SLIDE 50

Follow Along At Home

  • https://gitlab.com/asarazan/kotlinconf18
slide-51
SLIDE 51

Thank You

aaron@stencil.ltd https://gitlab.com/asarazan/kotlinconf18

slide-52
SLIDE 52 1

DSLs EVERYWHERE

slide-53
SLIDE 53

Kotlin’s Strongest Metaphors

Applied to Java’s biggest bummers

slide-54
SLIDE 54

How Did We Get Here?

slide-55
SLIDE 55

Value Types & Structs!!!

slide-56
SLIDE 56

Next Level DSLs

Configure your app the Kotlin way!

Aaron Sarazan CTO - Stencil Ltd. aaron@stencil.ltd

https://gitlab.com/asarazan/kotlinconf18

slide-57
SLIDE 57

How About That Keynote?

I can’t wait to get home and try out {AWESOME NEW FEATURE}

slide-58
SLIDE 58

Next Level DSLs

Configure your app the Kotlin way!

Aaron Sarazan CTO - Stencil Ltd. aaron@stencil.ltd

https://gitlab.com/asarazan/kotlinconf18

slide-59
SLIDE 59

Follow Along At Home

  • https://gitlab.com/asarazan/kotlinconf18
slide-60
SLIDE 60
slide-61
SLIDE 61
slide-62
SLIDE 62

Why Kotlin?