vendredi 21 mars 2008

Myth buster : Smarty sucks (part 2).

One can find some interesting discussions about Smarty and template engines [here].
New myth to bust :
  • With Smarty, we create too many templates, and the site becomes impossible to maintain.
I directly refer to this article. I hope the writer had honestly managed a large project with his method. Using OOP to output html is ineffective and inefficient. The success of PHP is a good example of what I'm talking about.

I would say that the maintainability of one site 's design essentially depends of the skills of the CSS engineer/dev rather than the number of templates.

  • Smarty is slow to process
Untrue. Show me your benchmark. For oolime projects, we benchmarked every single technology we are using, and I can tell you that the overload of Smarty is not critical. Moreover, the cache mechanism helps to speed up your website. With Smarty, we can put in cache chunks of HTML and assemble them when necessary. In some words, Smarty can cache the compiled template AND the output of any template.

I saw one "ignorant guy" (sorry for the adjective, but I couldn't find better :-) telling around the place that caching mechanism were useless if a website was fast enough...

  • We can do everything in PHP, so why using Smarty ?
Smarty is written in PHP so of course you can do everything that Smarty does in PHP. That's really a non valid argument. But beware of not reinventing the wheel for nothing...

About XSL
And when someone talks with me about xsl for HTML templating, I'm crying out loud. I've been developing templates and views in XSLT for three years before discovering how stupid XSLT is for this kind of tasks.

I needed to use DOM objects instead of PHP objects (and all the troubles of memory space & exec speed that it implies) the errors in the templates syntax were not explicit (blank html page syndrom), XSLT needs a long term investment for non interesting features for HTML (need to learn xpath, xslt, advanced xml)...

XSL is good to adapt XML data in a certain format (specified by a DTD or not) into another format.

mercredi 19 mars 2008

Myth buster : Smarty sucks (part 1).

On the one hand, MVC is one of the major design pattern in PHP world [wikipedia]. It provides a nice way to structure some programs.
On the other hand, Smarty is a templating engine for PHP. It is widely used and I recommend you to spend a couple of hours on it if you don't know it [smarty].
A little message from Planque on his blog criticizes the usage of Smarty to perform this famous MVC design pattern. We can see another here and there. The critics are quite different but all forget the same details about what is a good template engine. Let's try to make a synthesis of the complaints.
  • Smarty is more complicated than plain, old php with html.
Partly true. But being "complicated" is a big word here. Ten minutes and anyone who knows PHP does what he wants with Smarty. That's not like requiring a week of education and seminars...Anyhow sometimes being a bit more complicated provides nicies on the other side.

  • Smarty doesn't separate logic/business from view.
This point is the responsability of the developer. In SMarty, a dev can use the {php} tag to put any kind of php treatment in his template. These kind of operations does introduce logic in the template and therefore must be avoided But who can criticize Smarty on this point ? It was a choice between flexibility and structure. I would argue that any system must flexible in some way (and I know what I'm saying, I've been struggling with .NET platform for 7 months...). Or avoiding a trouble/bug/misconception can become a peplum.



Most part of the argument against smarty forgets one important part of a template system's job : caching mechanism. It is as simple as that.
Ans Smarty may do it quite well, although I didn't expertise this point.

So I wait for someone making a comparison of the different template engine, in term of efficiency, functionality.