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 It’s like an app, just smaller
Android Manifest
Plugin DSL
Plugin DSL
Plugin DSL
Plugin DSL
Plugin DSL
Back to Basics
Help! What’s a DSL?
When you really wish your language could do the thing.
Help! What’s a DSL? Java
Help! What’s a DSL? LISP
Help! What’s a DSL? Ruby
Podfiles
Help! What’s a DSL? Domain Specific Language
white space
Remove Boilerplate
Help! What’s a DSL? Domain Specific Language
Help! What’s a DSL? Domain Specific Language
Help! What’s a DSL? Domain Specific Language
Help! What’s a DSL? Domain Specific Language
You don’t DO the thing. You STATE the thing.
GRADLE!
Here’s How It Works
Here’s How It Works
Here’s How It Works
Experience Get!
Why Kotlin?
Groovy-Style Type-Safe Builders
It was literally built for it. Kotlin is made for DSLs
When Should I Make a DSL?
Anko
Anko
Anko
● XML This is Really Unpleasant ● Configuration ● Declaration ...and there has to be a better way. ● Boilerplate ● Builders
Builders ALWAYS a candidate for DSLs
Readability
Work Backwards Start from the result that you want to enable ...then write the code that enables it!
Start With Builders Immutability with a side of Java-friendliness!
@DslMarker Prevent Scoping Mishaps!
Don’t pollute the global namespace ● Good Hygiene 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. ○
Don’t pollute the global namespace ● Unary “+” only if well-scoped ● Good Hygiene Keep Lambda files next to your builder classes ● Plugin.kt ○ PluginLambdas.kt ○ Don’t extend system types ● String, Int, etc. ○ Have fun! ●
So Who’s Ready?
Follow Along At Home ● https://gitlab.com/asarazan/kotlinconf18
Thank You aaron@stencil.ltd https://gitlab.com/asarazan/kotlinconf18
DSLs 1 EVERYWHERE
Kotlin’s Strongest Metaphors Applied to Java’s biggest bummers
How Did We Get Here?
Value Types & Structs!!!
Next Level DSLs Configure your app the Kotlin way! Aaron Sarazan CTO - Stencil Ltd. https://gitlab.com/asarazan/kotlinconf18 aaron@stencil.ltd
How About That Keynote? I can’t wait to get home and try out {AWESOME NEW FEATURE}
Next Level DSLs Configure your app the Kotlin way! Aaron Sarazan CTO - Stencil Ltd. https://gitlab.com/asarazan/kotlinconf18 aaron@stencil.ltd
Follow Along At Home ● https://gitlab.com/asarazan/kotlinconf18
Why Kotlin?
Recommend
More recommend