Ben Godfrey

Encode project knowledge in XML

I went and sat and read the XSLT cookbook again. This time I read a bit about SVG but also the introduction to the chapter on code generation. The gist of it was that by encoding project knowledge in XML (or something similar) and using XSLT (or similar) to generate implementation files (of any form) you can adapt to changes in that source knowledge easily.

For example, I’m asked to build a website and as part of the design we decide to put tabs across the top of the page to link to the main areas of the site. When we begin the project we agree on six areas, but as I build the site I notice that two areas could be merged into one. Instead of having to change every page I’ve made so far (by hand or by Perl), I just tweak my knowledge file and set my stylesheets loose on it again.

I was discussing code generation with Miles recently and he raised the points that edge cases easily throw big spanners into the process and fixing these situations after the generation puts you at risk of regression errors. The knowledge encoding should be flexible enough to allow the author to identify edge cases (by some kind of pattern recognition most likely) and provide additional information that allows the transformation process to avoid making errors. Even if that is as simple as being able to include Ant tasks that use Perl or other external software to hack the implementation outputs.

I did try something similar once. WEBWAX was a system where you created a knowledge file for a website, that would be converted into the output site by XSLT. It worked quite well, but it was a bit inelegant. Having learned much more about XSLT since then and also having become familiar with Ant, I know I could write a much better system.

XML and XSLT are a great system for encoding knowledge and generating outputs because they have powerful friends. A knowledge file might be transformed into an Ant build file and a set of other XML documents. The Ant build process can perform a lot of work, moving files, running programs or even performing further transformations. Or the stylesheet could generate SVG so that you can create diagrams and graphics for documentation purposes. A website map could be generated easily in this way, as could ERDs for an application. XSLT can output any kind of text as well, plain text ain’t going out of fashion and it’s a route into many many systems.

Comments

Miles's avatar

Miles

Data-driven programming like this is definitely the way to go.Our project has a vast and complicated database schema, which is referenced by seven applications, and every time the database changes (which has been pretty frequent over the last month, like nearly every day), large chunks of code get broken. Of course, all this stuff doesn't get picked up at compile-time: it's only when I come to test it that we realise that the code hasn't been updated to reflect the changes. Worst of all, there's no way of identifying which database changes will break which bits of code - I looked at writing one, but due to the odd mix of tools and proprietary data formats we have to code against, no dice were forthcoming. It would be so, so much easier if we could tweak some XML and type "make" (or ant or whatever) and the apps would update.

There's some interesting stuff in The Art of Unix Programming about minilanguages - he recommends using minilanguages wherever possible to raise the abstraction level of your code. Previously this has been done with custom line-oriented formats (see /usr/share/units.dat, for instance) and/or full languages like awk or bc or flex, but now XML provides a less ad-hoc and more interoperable way of doing it.

Simon Cozens is working on something a bit more webby and closer to what it sounds like you need: see his blog.

Domain-specific languages seem to be big in the functional world as well: see Fran for an example.

Any chance you could make this edit box bigger?

Cancel

Comments are closed for this post.

Ben Godfrey http://aftnn.org

Not really... :-)
Cancel

Comments are closed for this post.

Add a new comment

Comments are closed for this post.