About the Book

Every time you design a domain model on your whiteboard, it seems to get lost in translation within the complex code base you started with. When you design your implementation model in your favorite programming language, it no longer speaks the dialect that the domain expert can understand. If your implementation on the whiteboard doesn’t conform exactly to the specifications you agreed on with the domain user, there’s no way it can be verified by the person who understands the domain rules.

DSLs in Action addresses this core issue by suggesting a DSL-driven application development model. Design your domain APIs around the syntax and semantics that the domain user understands. Then, even during the development of the code base, the user can do incremental verifications of the domain rule implementations. If your code speaks the language of the domain, it becomes clearer to the person who develops it, to the one who maintains it, and to a nonprogrammer domain expert who understands the business.

This book addresses the issues of using a DSL as well as implementing one. It talks about a DSL as a thin veneer of linguistic abstraction on top of an underlying semantic model. The semantic model is the implementation that manages the core structure of the domain, while the language layer speaks the dialect of the domain user.

You will learn how to design and implement DSLs using modern languages like Ruby, Groovy, Scala, and Clojure. The book discusses the strengths and weaknesses of the paradigms that these languages support in designing a DSL. By the time you’ve finished reading the book, you’ll have a thorough understanding of the concepts that you need to master in order to design beautiful domain abstractions that your user can understand and appreciate.

Who should read this book?

If you want to design good APIs that are expressive enough for your domain users as well as for your fellow programmers, this book is for you. If you’re a domain user and would like to improve your communication with the application development team, this book is for you. If you’re a programmer who feels the pain of trying to verify with your domain users whether the implementation of their business rules is correct, this book is for you as well.

Roadmap

Figures 1, 2, and 3 will give you an idea of how the book is organized and of what you can expect as you read it. The book has three parts:

  • Using DSLs
  • Implementing DSLs
  • Future trends in DSL development
Figure 1. Your journey through chapters 1 through 3

Figure 2. Your journey through chapters 4 through 6

Figure 3. Your journey through chapters 7 through 9

In part 1 (chapters 1-3), you’ll get a detailed overview of how a DSL-driven development environment fits into your application architecture. If you’re a programmer or an architect, this part of the book will help you adapt your current development stack with the new paradigm. The book is centered on languages that run on the Java Virtual Machine (JVM). If you’re a Java programmer, you’ll quickly determine how you can integrate your current Java-based project with DSLs that you develop in other, more expressive JVM languages.

Behind the user-friendly syntactic structures of a DSL is an underlying semantic model. Part 2 and chapters 7 and 8 focus on how to design the semantic model so that it acts as a good host for the linguistic abstractions of the DSL above it. This part of the book is more appropriate for developers who want to build beautiful abstractions as part of their domain model. Chapters 4 through 8 contain lots of DSL implementation snippets in languages like Ruby, Groovy, Clojure, and Scala. If you’re using one of these languages or planning to use them for your DSL implementation in the near future, you’ll find these chapters extremely useful. I start with basic DSL implementation techniques, then cover advanced techniques like metaprogramming, parser combinators, and frameworks like ANTLR and Xtext.

Part 3 (chapter 9) focuses on the future and techniques like parser combinators and DSL workbenches.

DSLs in Action is targeted at real practitioners. It contains theory, but only when it’s required for the purpose of understanding the implementation that follows. I wrote the book with the full and honest intention that it be useful to the developer community in the real world.

Typographical conventions

The book has a number of callouts and sidebars used to call your attention to important information.

In most cases, I’ve used the following sidebar template to present information related to the domain of securities trading and settlement:

 

Financial brokerage system

Information that’s accompanied by this icon contains something you should know to understand the domain that’s the focus of the DSL discussion. Special terms and concepts that you need some background information about are presented in these sidebars.

 

I’ve also included a number of callouts in the book that use the following template and icon:

 

These callouts contain information that stands out from the rest of the text in the section. The callouts might contain special idioms of DSL design, highlights from a discussion that we’ve recently had, or other nuggets that I want to emphasize.

 

I use one more icon in the book to attract your attention:

 

Information about individual languages

When you see this icon, you’ll know that the sidebar contains tidbits of information about the language used in the current examples. In order to fully understand the examples, you’ll need to be familiar with these specific concepts.

 

Be sure to read the extra information highlighted with these icons. It will help you to fully understand the ideas being discussed.

Code conventions and downloads

This book includes numerous example DSLs, many of which are substantial enough to explain complete domain rule implementations. The code is written in Java, Ruby, Groovy, Scala, and Clojure. Source code in listings or in text is in a fixed-width font to separate it from ordinary text. Method names, parameters, object properties, other scripts like those of ANTLR or Xtext, and XML elements and attributes in text are also presented in fixed-width font.

Source code can be verbose and detailed in order to provide a meaningful explanation of the semantics and the context. In many cases, the original source code has been reformatted, adding line breaks and reworking indentation, to accommodate the available page space in the book. In rare cases, this was not enough, and some listings include line continuation markers.

Code annotations accompany many of the source code listings, highlighting important concepts. In some cases, numbered bullets link to explanations that follow the listing.

I acknowledge that not all of you will be familiar with all the programming languages that I’ve used to implement the DSL structures. Keeping this in mind, I’ve included short reference cards (or cheat sheets) for the languages I discuss in appendixes C through G. These are not meant to be a complete reference for the language, but only brief pointers to the language features used in explaining the DSL implementations. References are provided to complete texts that you should read to supplement the cheat sheets.

Most of today’s IDEs are mature enough to let you develop projects in multiple languages. But, for those readers who aren’t familiar with the polyglot development environment, appendix G is a good starting point.

The source code for all examples in this book is available from Manning’s website, http://www.manning.com/DSLsinAction, which also contains relevant instructions on how to build and run them in your environment. Be sure to keep a copy of these listings when you go through the text.

Author Online

The purchase of DSLs in Action includes free access to a private web forum run by Manning Publications, where you can make comments about the book, ask technical questions, and receive help from the author and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/DSLsinAction. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions lest his interest stray! The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

About the author

Debasish Ghosh (@debasishg on Twitter) is the chief technology evangelist at Anshin-soft (http://www.anshinsoft.com), where he specializes in leading the delivery of enterprise-scale solutions for clients ranging from small to Fortune 500 companies. His research interests are OO and functional programming, DSLs, and NoSQL databases. He’s a senior member of the ACM and authors a programming blog at Ruminations of a Programmer (http://debasishg.blogspot.com). He can be reached at [email protected].

About the cover illustration

The figure on the cover of DSLs in Action is captioned “A man from Durdevac, near Osijek, Slavonija, Croatia.” The illustration is taken from a reproduction of an album of Croatian traditional costumes from the mid-nineteenth century by Nikola Arsenovic, published by the Ethnographic Museum in Split, Croatia, in 2003. The illustrations were obtained from a helpful librarian at the Ethnographic Museum in Split, itself situated in the Roman core of the medieval center of the town: the ruins of Emperor Diocletian’s retirement palace from around AD 304. The book includes finely colored illustrations of figures from different regions of Croatia, accompanied by descriptions of the costumes and of everyday life.

The village of Durdevac is near the town of Osijek in Slavonia, a geographical and historical region in eastern Croatia. Men in Slavonija traditionally wear red caps, white shirts, blue waistcoats, and pants with embroidered ornamentation. The final accessories are a wide woolen or leather belt and thick woolen socks, topped off with a jacket made from brown sheepskin, just like the figure on the cover of this book is wearing.

Dress codes and lifestyles have changed over the last 200 years, and the diversity by region, so rich at the time, has faded away. It is now hard to tell apart the inhabitants of different continents, let alone of different hamlets or towns separated by only a few miles. Perhaps we have traded cultural diversity for a more varied personal life—certainly for a more varied and fast-paced technological life.

Manning celebrates the inventiveness and initiative of the computer business with book covers based on the rich diversity of regional life of two centuries ago, brought back to life by illustrations from old books and collections like this one.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.77.250