Skip to Content
Programming Scala, 3rd Edition
book

Programming Scala, 3rd Edition

by Dean Wampler
May 2021
Intermediate to advanced
553 pages
13h 45m
English
O'Reilly Media, Inc.
Book available
Content preview from Programming Scala, 3rd Edition

Chapter 21. Domain-Specific Languages in Scala

A domain-specific language (DSL) is a programming language that mimics the terms, idioms, and expressions used among experts in the targeted domain. Code written in a DSL reads like structured prose for the domain. Ideally, a domain expert with little experience in programming can read, understand, and validate this code, if not also write code in the DSL.

We will just scratch the surface of this large topic and Scala’s support for it. For more in-depth coverage, see the DSL references in the Bibliography.

Well-crafted DSLs offer several benefits:

Encapsulation

A DSL hides implementation details and exposes only those abstractions relevant to the domain.

Productivity

Because implementation details are encapsulated, a DSL optimizes the effort required to write or modify code for application features.

Communication

A DSL helps developers understand the domain and domain experts to verify that the implementation meets the requirements.

However, DSLs also have several drawbacks:

DSLs are difficult to create

Although writing a DSL has been trendy, the effort shouldn’t be underestimated. The implementation techniques can be nontrivial. It’s difficult to account for all possible user errors and provide appropriate error handling and intuitive feedback. Good DSLs are harder to design than traditional APIs. The latter tend to follow language idioms for API design, where uniformity is important and easy to follow. In contrast, because ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Scala, 2nd Edition

Programming Scala, 2nd Edition

Dean Wampler, Alex Payne
Functional Programming in Scala, Second Edition

Functional Programming in Scala, Second Edition

Paul Chiusano, Runar Bjarnason, Michael Pilquist
The Go Programming Language

The Go Programming Language

Alan A. A. Donovan, Brian W. Kernighan

Publisher Resources

ISBN: 9781492077886Errata PageSupplemental Content