Use Conventions to Improve Fluency
When designing DSLs we should aim for the syntax to read like a natural language or a data input file. DSLs should be fluent and not feel like old C or C++ code. The code should be easy for nonprogrammers to write and just about anyone to read.
Suppose our banking application’s DSL needs to process a series of transactions that are posted as a stream of data. An example stream of data may look like this:
| account number 12345678 deposit 10025 |
| account number 12345678 deposit 15045 |
There are no unnecessary elements in that data file—it’s plain, simple, and to the point. As it turns out, that’s 100% bonafide Kotlin syntax, except we have to apply some conventions and bend some rules just a little to get it working. ...
Get Programming DSLs in Kotlin now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.