An opinion on PHP development
Posted by tim in It wouldn't fit in any other category... on December 16, 2008

It's been a while since I've talked about technical stuff and I need to rant, so here goes:

I got started in web development sometime around the middle of 2001... I think... Anyhow, it was a pretty garbled mess for me, as I picked up a couple of existing products and tried to make modifications to them to suit my needs. Frustrated, I ended up starting my own projects, and I have learned a lot even though not a single one is fully complete.

Along the way, I've played with all different technologies. I've used template engines, I've used frameworks, and I've even gotten my feet wet with some Ajax (without bleach :P). I've learned a lot from these, but there's one thing that holds true in all cases: Keep it simple, stupid.

Let's start from the top with template engines. It's kind of a good idea at first, because you may have your project broken out into groups of designers, developers, and managers. The designers may not know much about the core of your application -- the PHP that does all the heavy lifting -- but they may be quite skilled with XHTML and know how to do the needful. The problem with most template engines, though, is they introduce either a new markup language specific to the template system, or they use rather awkward methods using some sort of implementation of PHP.

For a long while I was a fan of Smarty. In fact, several of my sites still use Smarty. I thought it was a good idea because it helped me keep my presentation layer separate from my processing layer, and it allowed for me to make different themes for my sites. The downfall though was that I had to learn a new language that didn't really afford me the flexibility I needed, manipulating the data to suit the needs of the layout. Other developers pushed that I needed to not use a template engine and use straight PHP to build my layout. I didn't believe them, and when I first tried it after using Smarty, it was painful. But now that I've been working without any template engine for over a year, I can honestly say that PHP is beneficial from not only that standpoint, but also from a resource usage standpoint. No longer am I passing around arrays and classes up to 1MB in size. No, I'm now passing just the data I need, and using includes to load the different sections of my layout while maintaining my presentation layer separation.

The next problem is down to frameworks. Who in their right mind would consider building a simple list management system from a framework like symfony or Code Igniter? These frameworks are big, bulky, and are much too restrictive (unless you're new to the concept of project development entirely). It's possible to build a project from a very simplistic framework (which I'll be sharing my version of sometime in the next few months), and if you're diligent enough you can maintain a clean and organized project without sacrificing your power and ability as a developer. In short, frameworks like those mentioned are a horrible idea.

Ajax. Not the stuff I (don't) clean my kitchen sink with. No, the implementation of asynchronous JavaScript and XML. What's the problem with it? It's generally overdone (see Dojo Toolkit Demo: Contributor Listing), and pointless. Probably the only reasonable implementations I've seen so far are applications like Meebo and GMail. Generally speaking though, there's no point in using Ajax. It just over-complicates things and leaves you curled up in the corner of your office, sucking your thumb, and chanting obscenities against the technology of Ajax.

I guess in summary, I just want to say that I'm old-fashioned and I despise anyone who tries to get all fancy-schmancy with their code. You have a links database; you don't need a full MVC framework with an Ajax fisheye-flipper!


I'll have to disagree with you here on almost every point, but let me address your issues backwards (or atleast out of order) because that will wind up making the most sense.

Frameworks get a bad wrap, and mostly for good reason. But CodeIgniter is actually great. The problem with a lot of frameworks is that you wind up having to really throw yourself into this whole new programming paradigm and until you figure out the "proper" way to work within its constraints you feel a little lost and a lot slowed down. That, and there's only one right way to do things. CodeIgniter isn't this way, though. Everything it does is essentially that part of the beginning of a project where you sit and think, "alright... how am i going to do this..." except that with CodeIgniter you can just get started. And once you do, you're still free to do things your own way. Is it suitable for a simple link database? Probably not. For projects beyond that it's got so many benefits that I'd use it. Without actually getting your hands dirty with CI I'm not sure I can convince you of its benefits, but take my word for a moment that it's great.

Ajax was something that felt really daunting to go and try to learn for a long time, and I put it off. With libraries like jQuery today, though, Ajax is ridiculously easy (easier than not using it, honest to God). You wind up with a single page instead of two or more, so you spend less or equal time making the interface and you get the added benefit that a page load isn't necessary. As a side note, Json makes the whole thing so easy to do (just convert your PHP array to Jason, display it, and grab it with jQuery and you've got all your data in JS now... simple!) that Ajax development can honestly be a real treat.

As for template engines I'm still on the fence. With something like CodeIgniter you can deal with objects and methods rather than actual data passing. This means you're not having to pass around copies of data, which is great (not to mention it's the entire point of OOP). There's still some overhead attached to this and not all that many benefits, but some of the helper stuff can be pretty nice. Personally I've dropped using template engines altogether but I'd really like the idea of template engines if there was a standard template language. How great would it be if there was a single template language to rule them all and the backend wouldn't matter? I think that's the ideal situation. Until that happens, though, having the front-end guys learn something like Smarty is wasted time.

I think the whole way that web programming is shifting can be really bewildering at first, but ultimately it has rejuvenated my love for the craft. There's a balance somewhere between this "old way" and "new way" and I think I've found it with the combination of CodeIgniter and jQuery. Again, it really is a treat to work with.

  • Posted by Dustin (Guest) on December 18, 2008 at 12:56:08PM

Sans your CodeIgniter plug (Brought to you by Carl's Jr. :P), this is the type of meaningful response I have been dying for lately. Nobody, and I mean nobody I work with has the same level of knowledge or involvement in web development. There are a few who are getting started, but they normally come to me for advice and such. There is one of my co-workers who is a die-hard Ajax developer, but I've never had the opportunity to have a discussion with him about anything for more than 5 or 10 minutes.

Dustin, if you wouldn't keep falling off the face of the earth, I would be more than happy to discuss this type of thing with you on a regular basis again!

  • Posted by tim (Guest) on December 18, 2008 at 05:10:14PM
Add a comment