I realised recently that the dynamic mock object frameworks that I have worked on over the last few years are really an attempt to create embedded domain specific languages for specifying the expected outgoing calls of an object under test. The latest version of the dynamic mock object framework is jMock, written for the Java language. Java does not support embedded languages very well because of all the syntax it requires: round brackets here, curly braces there, square brackets somewhere else, type declarations and casts willy nilly. They all get in the way of what I want to write and read: the identifiers I have defined and literal values. It turns out that fiddling with the syntax colouring in Eclipse helps a great deal. Although the colouring rules are not fine grained enough to be perfect, slight changes in colour scheme have made my tests easier to read.
I would contend that the art of programming is the creation of languages in which you can express your solutions to problems in the application domain — that is, the creation of domain specific languages. Some programming languages, such as Forth, Haskell, LISP or Smalltalk, make it very easy to create domain specific languages because they provide the programmer with less instead of more. Each of those three languages has very little syntax, provides very few core abstractions and control structures, but gives the programmer powerful ways to combine existing abstractions into new abstractions. Java takes the opposite approach: it provides quite a few core abstractions with lots of syntax and limits the way that the abstractions can be smoothly combined. But we all know that Java is not the best language in the world. We use it for practical reasons and because the excellent tool support makes us very productive. So I tried a quick experiment to see if I could make my IDE of choice, Eclipse, support my use of a domain specific language.
My experiment involved fiddling with the syntax colouring to see if different colour schemes could make my mock object tests easier to read. Here's a test case displayed with the usual syntax colouring. The identifiers and values get a bit lost among all the brackets:
If I make the brackets the same colour as the background, the lines that set up expectations are now very descriptive, but the colour scheme is totally impractical for anything else. Furthermore, Eclipse gives the same colours to brackets as to commas, all operators and even decimal points!
But using 50% grey works nicely. Java's syntactic noise is still visible but now the identifiers and values stand out: