Petzold’s April Fool’s Joke

Hope you enjoyed the link to CSAML in our News section.

I think this is a very funny joke. Generally when a joke has to be explained, it is not considered funny, so I am not going to explain it but I’d like to discuss its significance because it relates very much to domain specific languages and to what is wrong with the current implementations.

It is important to realize that Charles Petzold’s examples are nearly real – they employ current techniques that people have to use for domain specific languages out of sheer necessity – but he applies them to the C# language where a highly usable but expensively developed syntax is already available. The contrast between the two – the luxurious C# and the cheap XML – is appalling and we find that funny in a kind of cruel “Upstairs, Downstairs” way – this was the British TV drama where the upper-class household upstairs was in contrast with the lower-class servants downstairs.

With projective systems you can have both great looks and inexpensive implementation. But there are two additional fine points: the source, no matter what is the notation, should not contain information that is computable from the rest. It should contain only things where the user is the only authority – that is the user’s intentions. For example, by this rule we could omit including the information that in the statement A=5/(B+27*C) the operand 27 is a multiplier, unlike in Petzold’s XML statements where an extra <Multiplication.Multiplier> tag was given. That information belongs in the definition of the multiplication, not in the source tree. Otherwise all we have is another hoop that the user and language transforming programs have to jump through.

The other point is that is that the awkwardness of XML and the lack of projections causes the language designers to intermittently fall back into text syntax.This happened, for example in the “Type” attribute of the joke: <Literal Type="{x:Type Int32}"> ; or in the XPath expressions of XSL in real life.

Here is how a similar example looks as an Intentional Tree:

Assign(A, Div(5, Plus(B,
Mul(27, C)))

In this instance the Mul definition already knows that the first argument is the multiplier.

When we project it in the Intentional Editor the editable screen looks like this:


Of course many other editable projections are also possible, here are just a few more for fun:




The interesting point is that even the “not-projected” representation is not at all terrible; it looks a little like LISP. It is not intended for normal use by people; it is a projection of the binary internal representation. The main reason that it looks better than the joke example is that it does not include any information that should be in the schemas, or which is part of the general domain knowledge, in other words it is Intentional. Of course, if you want the real XML syntax, like Petzold joked about, it is just another projection where the schema information is included. And with that you can say you are a real XML programmer with all the scars!