About This Title

Pages: 74
Published: March 2021
ISBN: 9781680507935
In Print

Skill Level Meter

Programming DSLs in Kotlin

Design Expressive and Robust Special Purpose Code

by Venkat Subramaniam

Creating your own domain-specific languages (DSLs) is both challenging and exhilarating. DSLs give users a way to interact with your applications more effectively, and Kotlin is a fantastic language to serve as a host for internal DSLs, because it greatly reduces the pain and effort of design and development. But implementing DSLs on top of Kotlin requires understanding the key strengths of the language and knowing how to apply them appropriately. Learn to avoid the pitfalls and leverage the language while creating your own elegant, fluent, concise, and robust DSLs using Kotlin.


About the Pragmatic Answers Series

Sometimes “right now” just isn’t soon enough. When you’re facing a hard deadline and need features that work and code that passes all the tests, there’s no time to hunt through forums and dubious blog posts hoping to stumble across a solution. You need accurate information from experts you trust. You need hands-on instruction that gets right to the point. You need Pragmatic Answers.

Ebook only and short (around 50 pages), the Pragmatic Answers Series gets you over the toughest hurdles in the blink of an eye.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $9.99 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Internal DSLs remove the burdens of implementing a full blown language compiler. The host language quickly becomes your ally to creating DSLs, but the syntax you can choose for your DSLs is limited to what the host language allows. You can work around the limitations by tactfully bending the rules and exploiting the language capabilities. Learn the power of Kotlin and ways to design with it, in the context of crafting internal DSLs.

Start by learning ways to exploit the flexibilities of Kotlin to make your DSLs fluent, expressive, and concise. Then pick up techniques to extend the language with domain specific properties and functions. Quickly move ahead to tie your DSL snippets into the runtime environment and context of execution of your applications. Design to prevent any non-sensical syntax in your DSL that may otherwise be valid in the host language. Finally, learn techniques to gracefully handle errors. Practice using the multiple examples that are included in each chapter.

Fire up your editor and follow along each example to become proficient in designing and implementing your own internal DSLs using Kotlin.

What You Need

Kotlin version 1.3 or later and your favorite Kotlin IDE or code editor.

Resources

Releases:

  • P1.0 2021/03/26
  • B2.0 2020/09/28
  • B1.0 2020/08/21

Contents & Extracts

  • Preface
    • Who Is This Book For?
    • What’s in This Book?
    • Online Resources
  • Introduction excerpt
    • Focus on the Key Characteristics
    • Kotlin as a Host Language
    • Steps to Program DSLs
  • Exploit Fluency excerpt
    • Remove Noisy Syntax
    • Design for Fluency
    • Make Syntax Obvious
    • Use Conventions to Improve Fluency
  • Get Domain Specific
    • Use Domain-Specific Extension Functions
    • Create Extension Operators
    • Use Domain-Specific Operators
    • Use invoke to Remove Redundant Syntax
  • Provide Contexts
    • Provide Context for Variables
    • Design for Separate Implicit Contexts
    • Use the Default Lambda Parameter Name for Context
    • Use Multiple Contexts to Remove Ambiguity
    • Use Inner Classes to Share State Between Contexts
  • Manage Scope and Handle Errors
    • Leverage the Compiler
    • Leverage Type Checking
    • Restrict Scope of Functions
    • Control Scope with DslMarker
    • Proactively Handle Errors
  • Practice with Examples
    • Let’s Design a Builder
    • Devise Ways to Run DSLs from External Sources

Author

Dr. Venkat Subramaniam is an award-winning author, founder of Agile Developer, Inc., and an instructional professor at the University of Houston. He has trained and mentored thousands of software developers in the US, Canada, Europe, and Asia, and is regularly invited to speak at international conferences. He’s the (co)author of multiple books, including the 2007 Jolt Productivity award winning book Practices of an Agile Developer and Programming Kotlin.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $9.99 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal

Related Titles:

Skill Level Meter

About This Title

Pages: 74
Published: March 2021
ISBN: 9781680507935
Edition: 1
In Print