The
roadmap for Martin Fowler's forthcoming book on DSLs indicates
that he will focus on textual DSLs. The online
draft of the
intro does however briefly show a graphical language for a home
security system: the model in
Figure 6 is implemented with MetaEdit+, based on the original
textual requirements:
Miss Grant has a secret compartment in her bedroom that
is normally locked and concealed. To open it she has to close the
door, open the second draw in her chest, turn her bedside light on
- and then the secret panel is unlocked for her to
open.
Juha-Pekka has been using Martin's example as a way of showing
how to implement a DSM language in MetaEdit+ (Parts
1 and
2 ), and in Part
3 he points out some problems with the original language: too
broad a focus, unclear usage process, and too low a level of
abstraction. Juha-Pekka correctly suggests going back to the basics
of the domain to discover the necessary language concepts, rather
than trying to shoehorn this domain into a generic state model.
As an exercise, however, I thought it might be interesting to try to
improve Martin's language as it is, rather than starting from
scratch. How much of DSM is "you just have to know how to do it",
and how much can be reduced to simple steps that anyone could
apply? Obviously, the more of the latter that we can find, the
easier it is for somebody to get started. Our
DSM book aimed at just this
kind of practical approach; let's take a few hints from there and
apply them to Martin's language. We'll show the model in the
current state of the language as we evolve it: click the pictures
to see the full size screenshot.
Use meaningful symbols
Martin's language uses just black and white shapes, the kind
you might see in a standard flow chart palette. Only the text
within the shapes gives a clue as to the actual domain: words like
"door", "drawer", "light" and "panel" occur many times. However, the brain takes a lot longer to find all occurrences of a word in a
picture than it does to find all occurrences of a symbol. Try it
yourself: how many times does the door symbol appear in the picture
on the right, and how many times does the word "door" appear in
Martin's
Figure 6? (You'll actually notice a slight discrepancy:
Martin's diagram omits the "reset all / return to start" event
caused by the door opening, shown at the extra door at the top left in our diagram;
he mentions this elsewhere in the draft.)
Reuse objects
Having four door objects like this obviously isn't ideal: Martin had them, but the problem wasn't so visible there because they a) couldn't be distinguished from other objects, and b) didn't so clearly represent something in the physical world -- the problem domain. Now that we have them visible, it would be nicer if we could show that there's really only one door in this model, and it is involved in four different events or actions. So let's merge the four doors into one, and similarly for the panel.
The light bulbs and drawers are harder: if we merge them, we end up with either lots of crossing lines, or objects on top of each other. Maybe there's something else we could do for them?
Raise the level of abstraction
Raising the level of abstraction often means "if you see a repeated pattern or sequence, make a single unit to represent that pattern".