Next Level DSLs

Next Level DSLs

Configure your app the Kotlin way!

Aaron will walk you through the design of a pluggable app architecture, all driven by an expansive domain-specific language executed at run-time.

Heavily inspired by the structure of build.gradle, this talk will demonstrate how you can push your configuration logic into a type-safe, declarative, and convenient format.

Source Code: https://gitlab.com/asarazan/kotlinconf18

6adc6ab076fa0dbd18371f5e95941fa1?s=128

Aaron Sarazan

October 04, 2018
Tweet

Transcript

  1. https://gitlab.com/asarazan/kotlinconf18 Next Level DSLs Configure your app the Kotlin way!

  2. Next Level DSLs Configure your app the Kotlin way!

  3. Next Level DSLs Configure your app the Kotlin way!

  4. None
  5. None
  6. None
  7. Isolated Feature Development

  8. A Plugin It’s like an app, just smaller

  9. Android Manifest

  10. Plugin DSL

  11. Plugin DSL

  12. Plugin DSL

  13. Plugin DSL

  14. Plugin DSL

  15. Back to Basics

  16. Help! What’s a DSL?

  17. When you really wish your language could do the thing.

  18. Help! What’s a DSL? Java

  19. Help! What’s a DSL? LISP

  20. Help! What’s a DSL? Ruby

  21. Podfiles

  22. Help! What’s a DSL? Domain Specific Language

  23. white space

  24. Help! What’s a DSL? Domain Specific Language

  25. None
  26. Help! What’s a DSL? Domain Specific Language

  27. Help! What’s a DSL? Domain Specific Language

  28. Help! What’s a DSL? Domain Specific Language

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

  30. GRADLE!

  31. Here’s How It Works

  32. Here’s How It Works

  33. None
  34. None
  35. Here’s How It Works

  36. Here’s How It Works

  37. Experience Get!

  38. When Should I Make a DSL?

  39. Anko

  40. Anko

  41. Anko

  42. This is Really Unpleasant ...and there has to be a

    better way. • XML • Configuration • Declaration • Boilerplate • Builders
  43. Builders ALWAYS a candidate for DSLs

  44. Readability

  45. Work Backwards Start from the result that you want to

    enable ...then write the code that enables it!
  46. Start With Builders Immutability with a side of Java-friendliness!

  47. @DslMarker Prevent Scoping Mishaps!

  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.
  49. 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.
  50. 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!
  51. Thank You aaron@stencil.ltd https://gitlab.com/asarazan/kotlinconf18