| 1 |
History of Cheetah |
| 2 |
================== |
| 3 |
|
| 4 |
|
| 5 |
In Spring 2001, several members of the webware-discuss mailing list |
| 6 |
expressed the need for a template engine. Webware like Python is |
| 7 |
great for organizing logic, but they both suffer when you need to |
| 8 |
do extensive variable interpolation into large pieces of text, or |
| 9 |
to build up a text string from its nested parts. Python's {%} |
| 10 |
operator gets you only so far, the syntax is cumbersome, and you |
| 11 |
have to use a separate format string for each nested part. Most of |
| 12 |
us had used template systems from other platforms-chiefly Zope's |
| 13 |
DTML, PHPLib's Template object and Java's Velocity-and wanted to |
| 14 |
port something like those so it could be used both in Webware |
| 15 |
servlets and in standalone Python programs. |
| 16 |
|
| 17 |
Since I (Mike Orr) am writing this history, I'll describe how I |
| 18 |
encountered Cheetah. I had written a template module called |
| 19 |
PlowPlate based on PHPLib's Template library. Like PHPLib, it used |
| 20 |
regular expressions to search and destroy-er, replace-placeholders, |
| 21 |
behaved like a dictionary to specify placeholder values, contained |
| 22 |
no directives, but did have BEGIN and END markers which could be |
| 23 |
used to extract a named block (subtemplate). Meanwhile, Tavis Rudd |
| 24 |
was also on webware-discuss and interested in templates, and he |
| 25 |
lived just a few hours away. So on 12 May 2001 we met in Vancouver |
| 26 |
at a gelato shop on Denman Street and discussed Webware, and he |
| 27 |
drew on a napkin the outline of a template system he was working |
| 28 |
on. |
| 29 |
|
| 30 |
[Note from Tavis: Mikes got the dates and sequence of things a |
| 31 |
little out of order, but what the hell ...] |
| 32 |
|
| 33 |
Instead of filling the template by search-and-replace, he wanted to |
| 34 |
break it up into parts. This was a primitive form of template |
| 35 |
compiling: do the time-consuming work once and put it to a state |
| 36 |
where you can fill the template quickly multiple times. A template |
| 37 |
without directives happens to break down naturally into a list of |
| 38 |
alternating text/placeholder pairs. The odd subscript values are |
| 39 |
literal strings; the even subscripts are string keys into a |
| 40 |
dictionary of placeholder values. The project was called |
| 41 |
TemplateServer. |
| 42 |
|
| 43 |
In a couple months, Tavis decided that instead of compiling to a |
| 44 |
list, he wanted to compile to Python source code: a series of |
| 45 |
{write} calls that would output into a file-like object. This was |
| 46 |
the nucleus that became Cheetah. I thought that idea was stupid, |
| 47 |
but it turned out that this not-so-stupid idea blew all the others |
| 48 |
out of the water in terms of performance. |
| 49 |
|
| 50 |
Another thing Tavis pushed hard for from near the beginning was |
| 51 |
"display logic", or simple directives like {#for}, {#if} and |
| 52 |
{#echo}. (OK, {#echo} came later, but conceptually it belongs here. |
| 53 |
I thought display logic was even stupider than compiling to Python |
| 54 |
source code because it would just lead to "DTML hell"-complicated |
| 55 |
templates that are hard to read and maintain, and for which you |
| 56 |
have to learn (and debug) a whole new language when Python does it |
| 57 |
just fine. But others (hi Chuck!) had templates that were |
| 58 |
maintained by secretaries who didn't know Python, and the |
| 59 |
secretaries needed display logic, so that was that. Finally, after |
| 60 |
working with Cheetah templates (with display logic) and PlowPlate |
| 61 |
templates (with just blocks rather than display logic), I realized |
| 62 |
Tavis was smarter than I was and display logic really did belong in |
| 63 |
the template. |
| 64 |
|
| 65 |
The next step was making directives for all the Python flow-control |
| 66 |
statements: {#while}, {#try}, {#assert}, etc. Some of them we |
| 67 |
couldn't think of a use for. Nevertheless, they were easy to code, |
| 68 |
and "somebody" would probably need them "someday", so we may as |
| 69 |
well implement them now. |
| 70 |
|
| 71 |
During all this, Chuck Esterbrook, Ian Bicking and others offered |
| 72 |
(and still offer) their support and suggestions, and Chuck gave us |
| 73 |
feedback about his use of Cheetah-its first deployment in a |
| 74 |
commercial production environment. Later, Edmund Lian became our #1 |
| 75 |
bug reporter and suggester as he used Cheetah in his web |
| 76 |
applications. |
| 77 |
|
| 78 |
We were going to release 1.0 in January 2002, but we decided to |
| 79 |
delay it until more people used it in real-world situations and |
| 80 |
gave us feedback about what is still needed. This has led to many |
| 81 |
refinements, and we have added (and removed) features according to |
| 82 |
this feedback. Nevertheless, Cheetah has been changing but stable |
| 83 |
since the late-binding rewrite in fall 2001, and anybody who keeps |
| 84 |
up with the cheetah-discuss mailing list will know when changes |
| 85 |
occur that require modifying one's template, and since most people |
| 86 |
use point releases rather than CVS, they generally have a few |
| 87 |
week's warning about any significant changes. |