Category Archives: Software Development

Smarty considered harmful

This post by Mike Morgan “Scalable PHP with APC, memcached and LVS (Part 2)” includes the increasingly popular opinion that Smarty is a waste of time.

I’ve used Smarty successfully in the past and been pleased with the result, particularly on Geograph where we need to maintain reasonable code quality with potentially many developers of varying levels. You’re forced to handle the presentation logic separately – a “good thing”.

I believe the primary purpose of any programming language is to communicate ideas and algorithms to other programmers – not computers. In this respect, PHP+Smarty does a good job.

However, while I like it and use it, I recognise one of the main failings of Smarty is debugging – the template is turned into PHP code which really wasn’t meant for human eyes. Single-step through it at your peril.

Pastebin doesn’t use Smarty, but then it only really has one page to display. However, to make it easy to integrate into other sites, it is templatable. It gathers all the data required on a page and then includes a separate php file to format it for display. Simple, yes, but has all the benefits of Smarty with the ability to debug it too.

In a wider sense, what’s really needed are more common patterns of PHP code structure to help push better practices out there. Getting smart without Smarty. The Zend Framework includes a Zend_Controller set of classes, which aid in adopting an MVC pattern. Too early to say whether it will take off, but it’s a good effort.

Maybe I should just switch to Ruby on Rails. It’s got everything I want, I’m just waiting for the right project to give it a decent crack of the whip…

PHP and Eclipse

Lukas Smith recently wrote about the development processes surrounding Zend’s planned Eclipse-based IDE.

I never really understood why Zend have duplicated the existing PHPEclipse effort, but Lukas’s post shed a little light on it. It’s certainly a shame that they don’t appear to have fully embraced the community element of open source development, but in the long run, a competing project might be good thing.

Every few months I give PHPEclipse a try. It looks great, but last time around a few minor bugs stopped it becoming my primary IDE. I submitted a bug report and the developers checked in a fix to CVS and I’ve been eagerly awaiting the next release ever since. Version 1.18 was released last week and I can’t wait to see if it’s ready for me to make the switch!

What I particularly liked with PHPEclipse was the live preview pane, where you can have the IDE request the file you are editing from the webserver. Great for front end UI work obviously, but even better when you’re developing a class. With a bit of effort, you can can configure your server to run a unit test for you. Edit, save, see test result….edit, save, see test result, doesn’t that sound great?

Whenever I do a little C++ development I use Microsoft Visual Studio, which is a fantastic IDE. It always leaves me hungry for the same features in my PHP environment. When you write C++, using the debugger is the norm, whereas in PHP, developers reach for a debugger as the very last resort (if at all). Hopefully things are a-changing…