[Catalyst] template comparison (was: why not mason (was: something else unrelated))

Jonathan Rockway jon at jrock.us
Fri Oct 27 18:02:47 GMT 2006


Max Afonov wrote:
> Why don't I _ever_ hear about Mason on this list? How is TT better than
> Mason anyway?
> 
> ...not meaning to start a flame war...

Mostly because mason becomes an unreadable mess, just like PHP.  Take a
look at the RT source code, or my clever example here:

Mason:

<table><% my $sth = $dbh->prepare('SELECT columns FROM table WHERE
something=1'); for($row = $sth->fetchrow_arrayref){ %></table>

That Other Language:

<table><?php $sth =
mysql_execute_a_query_or_something_omg_this_is_long("SELECT columns FROM
table WHERE something=1");
for(mysqllni_get_those_results_out_of_the_result_handle($sth) as $row){
print "<tr><td>". $row['0']. "</td><td>". $row['1']. "</td></tr>"; }
?></table>

TT (in Cat with DBIC):

<table>
[% WHILE (row = rows.next) %]
<tr>
  <td>[% row.name | html %]</td><td>[% row.whatever | html %]</td>
</tr>
[% END %]
</table>

ClearSilver (with some preparation in the view):

<table>
<?cs each:row = rows ?>
<tr><td><?cs var:name ?></td>
<td><?cs var:whatever ?></td></tr>
<?cs /each ?>
</table>

Mason and PHP are both fine tools, but they are a little too flexible.
If you want web designers to be able to work on your templates, then you
can't have "print" statements in your template.  If you want your code
to be maintainable, you can't prepare your database queries in the
template.  Mason and PHP degenerate to things like the above example
because it's really easy to let happen.  (Look at the RT source.  Good
people working on it.  Completely useless templates.)

TT definitely lets you write bad code too, but [% EVAL %] is off by
default (and hence I omitted it in my example).  ClearSilver ensures
that you don't do anything code-wise in your templates, at the cost of
not being able to do anything code-wise in your templates :)

Pick the system you like, but be aware of the problems that PHP and
Mason encourage.

Regards,

-- 
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;



More information about the Catalyst mailing list