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.
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: