summaryrefslogtreecommitdiff
path: root/docs/users_guide_src/comparisons.tex
blob: f2c4f88176dbb2f2df3abfb5a06f48dbb5ebd7df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
\section{Cheetah vs. [fill in the blank]}
\label{comparisons}

This appendix compares Cheetah with various other template/emdedded scripting
languages and internet development frameworks.  As Cheetah is similar to
Velocity at a superficial level you may also wish to read comparisons between
Velocity and other languages at
\url{http://jakarta.apache.org/velocity/ymtd/ymtd.html}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Which features are unique to Cheetah}
\label{comparisons.unique}

\begin{itemize}
\item The {\bf block framework} (section {inheritanceEtc.block})
\item Cheetah's powerful yet simple {\bf caching framework} (section
     \ref{TDL.placeholders.caching})
\item Cheetah's {\bf Unified Dotted Notation} and {\bf autocalling}
     (sections \ref{TDL.placeholders.unifiedDottedNotation} and
     \ref{TDL.placeholders.autocalling})
\item Cheetah's searchList (section \ref{TDL.placeholders.searchList})
     information.
\item Cheetah's \code{\#raw} directive (section \ref{directives.raw})
\item Cheetah's \code{\#slurp} directive (section \ref{directives.slurp})
\item Cheetah's tight integration with {\bf Webware for Python} (section
     \ref{webware})
\item Cheetah's {\bf SkeletonPage framework} (section
     \ref{webware.inheritance.skeletonPage})
\item Cheetah's ability to mix PSP-style code with Cheetah
     Language syntax (section \ref{customizing.plugins}) 
     Because of Cheetah's design and Python's flexibility it is
     relatively easy to extend Cheetah's syntax with syntax elements from almost
     any other template or embedded scripting language.
\end{itemize}

%% @@MO: Is #extend unique too?

%% @@MO: What about the new features we've been adding?

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Cheetah vs. Velocity}
\label{comparisons.velocity}

For a basic introduction to Velocity, visit
\url{http://jakarta.apache.org/velocity}.


Velocity is older, has a larger user base, and has better examples and
docs at the moment. Cheetah, however, has a number of advantages over
Velocity:
\begin{itemize}
\item Cheetah is written in Python. Thus, it's easier to use and extend.
\item Cheetah's syntax is closer to Python's syntax than Velocity's is to
Java's.
\item Cheetah has a powerful caching mechanism.  Velocity has no equivalent.
\item It's far easier to add data/objects into the namespace where \$placeholder
     values are extracted from in Cheetah.  Velocity calls this namespace a 'context'.
     Contexts are dictionaries/hashtables. You can put anything you want into a
     context, BUT you have to use the .put() method to populate the context; 
     e.g.,

\begin{verbatim}
VelocityContext context1 = new VelocityContext();
context1.put("name","Velocity");
context1.put("project", "Jakarta");
context1.put("duplicate", "I am in context1");
\end{verbatim}
     
     Cheetah takes a different approach. Rather than require you to manually
     populate the 'namespace' like Velocity, Cheetah will accept any existing
     Python object or dictionary AS the 'namespace'.  Furthermore, Cheetah
     allows you to specify a list namespaces that will be searched in sequence
     to find a varname-to-value mapping.  This searchList can be extended at
     run-time.
     
    If you add a `foo' object to the searchList and the `foo' has an attribute
    called 'bar', you can simply type \code{\$bar} in the template.  If the
    second item in the searchList is dictionary 'foofoo' containing
    \code{\{'spam':1234, 'parrot':666\}}, Cheetah will first look in the `foo'
    object for a `spam' attribute.  Not finding it, Cheetah will then go to
    `foofoo' (the second element in the searchList) and look among its
    dictionary keys for `spam'.  Finding it, Cheetah will select
    \code{foofoo['spam']} as \code{\$spam}'s value.

\item In Cheetah, the tokens that are used to signal the start of
     \$placeholders and \#directives are configurable. You can set them to any
     character sequences, not just \$ and \#.
\end{itemize}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Cheetah vs. WebMacro}
\label{comparisons.webmacro}

For a basic introduction to WebMacro, visit
\url{http://webmacro.org}.

The points discussed in section \ref{comparisons.velocity} also apply to the
comparison between Cheetah and WebMacro.  For further differences please refer
to \url{http://jakarta.apache.org/velocity/differences.html}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Cheetah vs. Zope's DTML}
\label{comparisons.dtml}

For a basic introduction to DTML, visit
\url{http://www.zope.org/Members/michel/ZB/DTML.dtml}.

\begin{itemize}
\item Cheetah is faster than DTML.
\item Cheetah does not use HTML-style tags; DTML does.  Thus, Cheetah tags are
     visible in rendered HTML output if something goes wrong.
\item DTML can only be used with ZOPE for web development; Cheetah can be
     used as a standalone tool for any purpose.
\item Cheetah's documentation is more complete than DTML's.
\item Cheetah's learning curve is shorter than DTML's.
\item DTML has no equivalent of Cheetah's blocks, caching framework, 
     unified dotted notation, and \code{\#raw} directive.
\end{itemize}

Here are some examples of syntax differences between DTML and Cheetah:
\begin{verbatim}
<ul>
<dtml-in frogQuery>
 <li><dtml-var animal_name></li>
</dtml-in>
</ul>
\end{verbatim}

\begin{verbatim}
<ul>
#for $animal_name in $frogQuery
 <li>$animal_name</li>
#end for
</ul>
\end{verbatim}

\begin{verbatim}
<dtml-if expr="monkeys > monkey_limit">
  <p>There are too many monkeys!</p>
<dtml-elif expr="monkeys < minimum_monkeys">
  <p>There aren't enough monkeys!</p>
<dtml-else>
  <p>There are just enough monkeys.</p>
</dtml-if>
\end{verbatim}

\begin{verbatim}
#if $monkeys > $monkey_limit
  <p>There are too many monkeys!</p>
#else if $monkeys < $minimum_monkeys
  <p>There aren't enough monkeys!</p>
#else
  <p>There are just enough monkeys.</p>
#end if
\end{verbatim}

\begin{verbatim}
<table>
<dtml-in expr="objectValues('File')">
  <dtml-if sequence-even>
    <tr bgcolor="grey">
  <dtml-else>
    <tr>
  </dtml-if>    
  <td>
  <a href="&dtml-absolute_url;"><dtml-var title_or_id></a>
  </td></tr>
</dtml-in>
</table>
\end{verbatim}

\begin{verbatim}
<table>
#set $evenRow = 0
#for $file in $files('File')
  #if $evenRow
    <tr bgcolor="grey">
    #set $evenRow = 0
  #else
    <tr>
    #set $evenRow = 1
  #end if
  <td>
  <a href="$file.absolute_url">$file.title_or_id</a>
  </td></tr>
#end for
</table>
\end{verbatim}

The last example changed the name of \code{\$objectValues} to 
\code{\$files} because that's what a Cheetah developer would write.
The developer would be resposible for ensuring \code{\$files} returned a 
list (or tuple) of objects (or dictionaries) containing the attributes (or
methods or dictionary keys) `absolute\_url' and `title\_or\_id'.  All these
names (`objectValues', `absolute\_url' and `title\_or\_id') are standard parts
of Zope, but in Cheetah the developer is in charge of writing them and giving
them a reasonable behaviour.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Cheetah vs. Zope Page Templates}
\label{comparisons.zpt}

For a basic introduction to Zope Page Templates please visit
\url{http://www.zope.org/Documentation/Articles/ZPT2}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Cheetah vs. PSP, PHP, ASP, JSP, Embperl, etc.}
\label{comparisons.pspEtc}

[This section is under construction.]

\begin{description}
\item[Webware's PSP Component] -- \url{http://webware.sourceforge.net/Webware/PSP/Docs/}
\item[PHP Home Page] -- \url{http://www.php.net/}
\item[Tomcat JSP Information] -- \url{http://jakarta.apache.org/tomcat/index.html}
\item[ASP Information at ASP101] -- \url{http://www.asp101.com/}
\item[Embperl] -- \url{http://perl.apache.org/embperl/}
\end{description}


Here's a basic Cheetah example:
\begin{verbatim}
<TABLE>
#for $client in $service.clients
<TR>
<TD>$client.surname, $client.firstname</TD>
<TD><A HREF="mailto:$client.email" >$client.email</A></TD>
</TR>
#end for
</TABLE>
\end{verbatim}

Compare this with PSP:

\begin{verbatim}
<TABLE>
<% for client in service.clients(): %>
<TR>
<TD><%=client.surname()%>, <%=client.firstname()%></TD>
<TD><A HREF="mailto:<%=client.email()%>"><%=client.email()%></A></TD>
</TR>
<%end%>
</TABLE>
\end{verbatim}


% Local Variables:
% TeX-master: "users_guide"
% End: