in reply to RFC - Template::Empty

“Mixing code and HTML” a la PHP definitely turned out to be “a very-appealing mistake,” but I don't know that it's right to go to the opposite extreme.

The essential mistake that PHP made was to attempt to completely-merge the output and processing stages. What was good for simple websites (such as were common when PHP was first invented) turned out to scale poorly, and as a consequence of this, PHP developers have adopted templating systems.

I happen to like the approach that is used by systems such as Template Toolkit. This system has a moderately-complex meta-language but it's strictly for output-formatting. The “thinking” comes first, then the output-preparation follows. The two are not interleaved.

In a curious way, I think that the approach you are recommending here does “interleave” these two concerns, in an improper way. It is simply the opposite-extreme: the display-preparation is simply shifted into Perl, and HTML-generation is reduced to a perfunctory, “empty,” non-task.

The advantage of a good templating system, meta-language and all, is that a graphic designer can completely express a display task, given a description of what information has been pre-arranged into what variables. Meanwhile, the programmer can completely ignore that same display task, his-or-her concern only being to get the right information pre-arranged into the right variables. We all know that most “changes” that are requested, once a site has been first delivered, are cosmetic changes... involving a sometimes-substantial rearrangement and re-presentation of the same data. If what we are re-arranging is, indeed, “the same data,” then a suitably-smart templating system works to our advantage since once again it will be the graphic-designer who's doing most of the work. Changes to the underlying Perl-code are needed only for the new functionality, not to re-arrange the old functionality. I am not of the opinion that this “empty” approach would really allow that.

Replies are listed 'Best First'.
all data munging is push style templating
by metaperl (Curate) on Feb 25, 2008 at 16:21 UTC
    the display-preparation is simply shifted into Perl, and HTML-generation is reduced to a perfunctory, “empty,” non-task.
    HTML is empty and a non-task... HTML-generation is not empty at all. How can you call writing methods to manipulate HTML empty?

    and what you call a "simple shift" from pull style to push style is proven to create a more powerful templating system: the weakest push-style system is the strongest pull-style...

    In a curious way, I think that the approach you are recommending here does “interleave” these two concerns, in an improper way. It is simply the opposite-extreme: the display-preparation is simply shifted into Perl, and HTML-generation is reduced to a perfunctory, “empty,” non-task.
    What you call the "opposite-extreme" is actually best practice for data processing: processor and processed are completely separated, allowing flexible object-oriented composition.

    Processing HTML need be no different than best practice for XML, databases, LDAP and so on .

    But I am the person running Wordpress blogs, and drooling over Drupal for all of my personal sites. So while we both agree from a philosophical standpoint on how "WRONG" PHP is, we really both need to shut up and out-deliver. When we have useable web products on par with PHP, then our products can do the talking instead of the idle and empty chatter we are engaging in here.

    I have beheld the tarball of 22.1 on ftp.gnu.org with my own eyes. How can you say that there is no God in the Church of Emacs? -- David Kastrup
    [tag://etl,templating]
    Enforce strict model-view separation in template engines via HTML::Seamstress The car is in the cdr, not the cdr in the car
      PHP's success has little to do with syntax, or model/view interleaving. PHP is successful because it is extremely easy to deploy and offers minimal sandboxing.

      I use CGI perl or mod_perl for all of my web based development. But I would not say that perl is as easy to deploy as PHP. If perl had a simple, more "secure-for-the-average-hosting-provider" sandboxing scheme, then you'd see perl more available and potentially as widely adopted as PHP is.

      A discussion of PHP vs Perl is barely related to a discussion of the merits of template systems.

      my @a=qw(random brilliant braindead); print $a[rand(@a)];