Why templating systems are the wrong answer for simple HTML generation

January 15, 2009

One common proposed solution to the problem of simple HTML generation is a templating system. Apart from any practical issues (all of which can be worked around), I've come to realize that I believe that they're the wrong answer in general, because templating systems are solving a different problem.

At least for me, the problem simple HTML generation solves is that HTML is annoyingly verbose and picky to write directly by hand (and partly as a result is difficult to cleanly embed into Python code). This is the same problem that is solved for by using simple markup, and it's such a popular thing to do for the same reason that high level languages are popular: you want to have a compact and clear way of expressing your intentions, one that's quick to write and is not cluttered up with unimportant details.

The problem that templating systems solve is that if you try to generate complex pages in string-bashing code, you wind up with a horrible entangled mishmash of code and HTML that is effectively unreadable; you can't easily see either the shape of the HTML that will come out the end or what the code is doing. This is an important problem, but it is a different problem than not having to write HTML by hand; a solution to one is not necessarily a solution to the other.

(Some templating systems also try to solve the 'HTML is annoying to write' problem, but often they do not. In fact, one popular model for templating systems is HTML plus additional markup, which is exactly the reverse of what you want for simple HTML generation.)

Written on 15 January 2009.
« Documenting the kernel.sem sysctl
A lament about modern NFS development »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Thu Jan 15 02:40:35 2009
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.