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.

Aucun commentaire: