in reply to To Dance or not to Dance with Dancer2? That is the question.

We seem to have established that the question isn't really "Dancer vs. my homebrew webapp framework", but rather "templated HTML vs. my homebrew HTML generator". So, then, what do templates buy you?

Simplicity, for one. I glance at the TT (Template Toolkit) template in your post and immediately understand what it is, what fields the form has, etc. Aside from being several times as long, I need to actually read your HTML generation code and think about what it says before I can figure out what it's going to create. To be honest, when I read your post and saw "I'm not impressed with this small HTML template and consider this huge mass of Perl to be a 'simple amount of code'", I initially suspected you were joking.

The biggest thing that using templated HTML instead of generated HTML buys you, though, is separation of concerns. Your Perl code just stuffs all the data into a hash (or whatever other data structure) and hands it off to the template engine, then the template engine uses the template to figure out how to display that. This lets you do things like provide a basic HTML version of some data, a fancy HTML version of that same data, an XML version to feed to other software, a JSON version to feed to yet other software, and a CSV version for exports, all with no changes to the Perl code. All you have to do is specify a different template to the same underlying data structure.

A nice side effect of this separation is that, if you don't want to get your hands dirty with HTML editing (and I can't blame you; I avoid the stuff as much as I can, too), you can pass it off to actual web designers and let them create hand-crafted, artisanal HTML with all the bells and whistles and latest design fads, then turn that into a template (usually a simple process, or, if you're lucky, you might find a designer willing to learn to create templates himself) and you're good to go. And when the next design fad hits, it's just a new template away. You can even keep the old template available and let users choose which version they want to see.

  • Comment on Re: To Dance or not to Dance with Dancer2? That is the question.

Replies are listed 'Best First'.
Re^2: To Dance or not to Dance with Dancer2? That is the question.
by Dallaylaen (Chaplain) on Dec 06, 2017 at 22:31 UTC

    Excellent point: TT is instantly recognizable by anyone who has ever dealt with TT. I didn't even notice how instantly that was.