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

A. Pagaltzis pagaltzis at gmx.de
Fri Oct 27 23:01:37 BST 2006


* Jonathan Rockway <jon at jrock.us> [2006-10-27 20:10]:
> 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>

Why aren’t you presuming Catalyst::View::Mason and using a $rows
passed in from outside? This ain’t an apples-to-apples comparison
otherwise.

> 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>

    <table>
        <tr t:repeat="row rows">
            <td t:content="row/name">This is the row name</td>
            <td t:content="row/whatever">The row’s whatever</td>
        </tr>
    </table>

That’s TAL. My, is it readable.

> TT definitely lets you write bad code too, but [% EVAL %] is
> off by default (and hence I omitted it in my example).

You don’t need EVAL to write complex logic in TT. The builtin
minilanguage is perfectly sufficient for that – of course, since
its grammar is arbitarily limited and non-orthogonal and the
language is missing many abstractions, the result ends up looking
even more hideous than if you’d used a real language in the first
place.

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

My theory is that those systems encourage problems because they
do not hit the 80-18-2 mark[1]: a template is 80% static strings,
18% trivial logic like the examples you gave above, and 2% hairy
annoying display logic, usually when the template has to deal
with some non-predigested data structure. (If you predigest the
data structure, you’re just leaking display logic back into the
business logic.)

PHP and Mason fail in the ways you describe because they use
their provision for the 2% to also cover the 18% needs, thus
encouraging overuse of its power.

TT2 provides a single minilanguage for both, which is
unnecessarily powerful and verbose for the 18% and way
underpowered for the 2%.

TAL has the *perfect* syntax to cover the 18%, but leaves you
high and dry with the 2%.

They all suck, but at this point I hate TT2’s neither-fish-nor-
fowl approach more than any of them. TT2 has many things to
commend it, but its language is not of them.

None of these engines provides a separate concise syntax to cover
the 18% AND the power of a *real* language to cover the 2%.

I posit that having a real language available in templates would
not lead to problems if an alternative syntax were available that
was much easier to use for trivial display logic than firing up
the Turing-complete gun.


[1]: I pulled those numbers out of somewhere, purely on the basis
     that the combination should flow well as prose.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the Catalyst mailing list