The Customization Pit
Applying the simple DSL pattern can make it easy to create a solution to your problem as long as the solution can be expressed fully in the DSL. But what if you want to create something slightly different? If there are no other facilities available for modifying the solution, then you have a "customization pit" (Figure 1-16)—within the boundaries of what the DSL can express, things are easy and comfortable, but outside of those boundaries, things are difficult or impossible.
Figure 1-16 Customization pit
We'd much prefer the situation shown in Figure 1-17, where stepping out of the area covered by the DSL doesn't cause you to scale the walls of a deep pit but simply to step up onto a different plateau where things may be a little more difficult, but not impossibly hard. Beyond that plateau, there are further plateaus, each extending your capability to make solutions if you are willing and able to acquire the extra skills to go there. Alan Kay, the coinventor of Smalltalk, said, "Simple things should be simple. Complex things should be possible." We'd like to go a little further than that, and have difficulty increase only gradually as things get more complex.
Figure 1-17 Customization staircase
There are several techniques that we can employ to achieve this. The first is to employ multiple DSLs, each one handling a different dimension of complexity in the problem, as depicted in Figure 1-18.
Figure 1-18 Multiple DSLs
A second technique, and one which we employ extensively in the design of the DSL Tools themselves, is to generate code that is explicitly designed to be extended. The C# 2.0 feature of partial classes is particularly helpful here, because part of a class can be generated while leaving other parts of the class to be written by hand. In the case of DSL Tools themselves, where the generated designer is hosted in Visual Studio, these code extensions can call upon facilities provided by the host, such as the user interface or the project system.
A third technique, which you might think of as stepping up onto a higher-level expert plateau, is to enable the developer to modify the code-generation mechanisms, thus changing the way that the DSL is integrated into its environment. This requires yet more skill, because making it work correctly requires deeper knowledge of the remainder of the code.
The final technique represented by the highest plateau is to alter the implementation of the supporting platform, because it simply isn't capable of supporting the required features.