200909.21

Why I hate smarty

Smarty is everyone's favorite templating language for PHP. It's great in many ways, one of the main features being that it can display things on a website. It also promotes separation of display code and logic, which many PHP programmers seem to have trouble with: oscommerce, PHPList, etc etc.

So why do I hate it?

There's no fucking point! All bad programmers write bad code. Why create a language within a language just to force bad programmers to do one thing right? I realize that Smarty does enforce separation of logic from display very well. I've used it in several projects. But if its capabilities are so strikingly similar to PHP that for most things there is a 1-1 reference, why bother? Why not just use PHP code?

Also, the plugins (and {php} tag) allow you to make logical decisions, run mysql queries, send rockets to the moon...there's nothing you can do in PHP that you cannot do in Smarty...which makes Smarty completely worthless for what it's trying to do.

If you want to promote good programming, you don't need Smarty. You can rewrite Smarty as a PHP object that sets variables and includes a template. I've written this a dozen times over...and it does the exact same thing, except templates are in PHP so everyone can understand them, there is no caching trickery going on, and best of all you don't need to reference some stupid guide on how to display something in a strange language which you already know how to do in PHP.

So, in summation, please don't stop using Smarty. It's a good piece of code for people who don't understand the basics of separation of logic from display...but realize that Smarty is a hack, a patch, a band-aid. The REAL problem is bad programming, not something inherently wrong with PHP that needs to be rewritten.