Last night I was going to blog about the how the second system is the inherently dangerous, according to Frederick P. Brooks. As I researched it though, I came across Greenspun's Tenth Rule, which was an interesting read. In short, it says that any sufficiently complicated C or Fortran program contains a buggy implementation of Common Lisp.
It's taken me a few hours for this material to coalesce in my brain, but it seems like templating languages suffer from this same fate. I don't want a lot from templating languages. I want to be able to take some data that my application has generated, throw it at a template, and have it do what I expect.
When I started out with Mason many moons ago, it did exactly that. It was friggin' great. But Mason has all these hooks and cool features which can be (and often are) abused by programmers spending lots of time trying to save themselves future work by implementing shortcuts. Eventually, a fair amount of work goes into debugging these shortcuts, and it's evident that any expected economies of scale are falsehoods due to the fact that the maintenance cost for those shortcuts becomes overwhelming. Mason::Strict anyone??
So later on I started using Template Toolkit. I thought "This is great, I can throw objects at templates and it just works." Then I started working with more experienced template toolkit users, who knew it well enough that they were able to use it as a programming language, not just a templating language. Therein lay the danger. I managed to generate all sorts of esoteric runtime errors due to the fact that my macros didn't have the correct syntax, or some other crap that perl usually catches at compile time (and tells me the line number where the error is, instead of the package).
Along the way I used HTML::Template, which was nice also, but it was too strict for my liking. I couldn't throw objects at it, I had to serialize the objects into hashes. And I had to consult the docs to perform rudimentary operations such as loops, which I had committed to memory from perl.
So here I present to you Moyer's Eleventh Rule of Templating Languages. "Any sufficiently complicated templating language contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Perl". Take it for what it is worth, preferably with a large grain of salt. Most templating languages aren't perfect, and neither am I