Chapter 19. Domain-specific languages

 

This chapter covers

  • Understanding domain-specific languages (DSLs)
  • Writing DSLs in Groovy
  • Creating readable and expressive languages
  • Testing, securing, and providing good error reporting when creating DSLs

The limits of my language are the limits of my world.

Ludwig Wittgenstein

Domain-specific languages are languages tailored toward representing a particular domain of knowledge. Proponents of development methodologies suggest that what leads to success or failure of a project is the quality of communication and a common goal of producing software that delivers on promises of solving a particular domain problem.

Languages are at the root of any kind of communication and involve two interlocutors. A subject matter expert (SME) can write specifications in their mother tongue, say, English, with tons of domain-specific words and concept names that will be read by software developers. A developer can also speak to a computer using different languages to tell it about the business rules of the application the SME is longing to play with. The former will use a natural language while the latter will use one or several general-purpose programming languages.

19.1. Groovy’s flexible nature

19.2. Variables, constants, and method injection

19.3. Adding properties to numbers

19.4. Leveraging named arguments

19.5. Command chains

19.6. Defining your own control structures

19.7. Context switching with closures

19.8. Another technique for builders

19.9. Securing your DSLs

19.10. Testing and error reporting

19.11. Summary

sitemap