Chapter 3. The drive toward DSLs

In this chapter

  • Understanding DSL types
  • Building a DSL for scheduling tasks
  • Fleshing out a DSL syntax
  • Taking a DSL apart to see what makes it tick
  • Implementing the Scheduling DSL

In this chapter, we’re going to look at the different types of DSLs that we can build and at how and when we should use them. We’ll then take a problem—the need for a scheduling system—and begin solving it with a DSL—the Scheduling DSL. We’ll start by looking at the problem, follow the reasoning that leads us to solving it using a DSL, and then decide on the syntax and implementation.

In this chapter, we’ll build several implementations of the Scheduling DSL and go through the entire process of building a DSL for real use, although it will be a rather basic one.

3.1. Choosing the DSL type to build

The first step in building a DSL is deciding what type of a DSL to build. Our sample scenario will be scheduling tasks, so we’ll take a look at several approaches to building a scheduling DSL, which will help us compare fluent interfaces and DSLs.

First, we need to consider the steps involved in scheduling tasks, from the usage perspective: defining named tasks, defining the repeatability of the task, and defining the set of actions that will occur when the task is executed. Here are some examples of each:

3.2. Building different types of DSLs

3.3. Fleshing out the syntax

3.4. Choosing between imperative and declarative DSLs

3.5. Taking a DSL apart—what makes it tick?

3.6. Combining domain-driven design and DSLs

3.7. Implementing the Scheduling DSL

3.8. Running the Scheduling DSL

3.9. Summary

sitemap